Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tellduslive refactoring #18780

Merged
merged 7 commits into from
Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ omit =
homeassistant/components/tahoma.py
homeassistant/components/*/tahoma.py

homeassistant/components/tellduslive.py
homeassistant/components/tellduslive/__init__.py
homeassistant/components/tellduslive/entry.py
homeassistant/components/*/tellduslive.py

homeassistant/components/tellstick.py
Expand Down
4 changes: 2 additions & 2 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ homeassistant/components/*/simplisafe.py @bachya
# T
homeassistant/components/tahoma.py @philklei
homeassistant/components/*/tahoma.py @philklei
homeassistant/components/tellduslive.py @molobrakos @fredrike
homeassistant/components/*/tellduslive.py @molobrakos @fredrike
homeassistant/components/tellduslive/*.py @fredrike
homeassistant/components/*/tellduslive.py @fredrike
homeassistant/components/tesla.py @zabuldon
homeassistant/components/*/tesla.py @zabuldon
homeassistant/components/thethingsnetwork.py @fabaff
Expand Down
6 changes: 4 additions & 2 deletions homeassistant/components/binary_sensor/tellduslive.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
"""
import logging

from homeassistant.components.tellduslive import TelldusLiveEntity
from homeassistant.components import tellduslive
from homeassistant.components.binary_sensor import BinarySensorDevice
from homeassistant.components.tellduslive.entry import TelldusLiveEntity

_LOGGER = logging.getLogger(__name__)

Expand All @@ -19,8 +20,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up Tellstick sensors."""
if discovery_info is None:
return
client = hass.data[tellduslive.DOMAIN]
add_entities(
TelldusLiveSensor(hass, binary_sensor)
TelldusLiveSensor(client, binary_sensor)
for binary_sensor in discovery_info
)

Expand Down
9 changes: 4 additions & 5 deletions homeassistant/components/cover/tellduslive.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
"""
import logging

from homeassistant.components import tellduslive
from homeassistant.components.cover import CoverDevice
from homeassistant.components.tellduslive import TelldusLiveEntity
from homeassistant.components.tellduslive.entry import TelldusLiveEntity

_LOGGER = logging.getLogger(__name__)

Expand All @@ -19,7 +20,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
if discovery_info is None:
return

add_entities(TelldusLiveCover(hass, cover) for cover in discovery_info)
client = hass.data[tellduslive.DOMAIN]
add_entities(TelldusLiveCover(client, cover) for cover in discovery_info)


class TelldusLiveCover(TelldusLiveEntity, CoverDevice):
Expand All @@ -33,14 +35,11 @@ def is_closed(self):
def close_cover(self, **kwargs):
"""Close the cover."""
self.device.down()
self.changed()

def open_cover(self, **kwargs):
"""Open the cover."""
self.device.up()
self.changed()

def stop_cover(self, **kwargs):
"""Stop the cover."""
self.device.stop()
self.changed()
fredrike marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 6 additions & 5 deletions homeassistant/components/light/tellduslive.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
"""
import logging

from homeassistant.components import tellduslive
from homeassistant.components.light import (
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light)
from homeassistant.components.tellduslive import TelldusLiveEntity
from homeassistant.components.tellduslive.entry import TelldusLiveEntity

_LOGGER = logging.getLogger(__name__)

Expand All @@ -19,21 +20,21 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Tellstick Net lights."""
if discovery_info is None:
return
add_entities(TelldusLiveLight(hass, light) for light in discovery_info)
client = hass.data[tellduslive.DOMAIN]
add_entities(TelldusLiveLight(client, light) for light in discovery_info)


class TelldusLiveLight(TelldusLiveEntity, Light):
"""Representation of a Tellstick Net light."""

def __init__(self, hass, device_id):
def __init__(self, client, device_id):
"""Initialize the Tellstick Net light."""
super().__init__(hass, device_id)
super().__init__(client, device_id)
self._last_brightness = self.brightness

def changed(self):
"""Define a property of the device that might have changed."""
self._last_brightness = self.brightness
super().changed()

@property
def brightness(self):
Expand Down
17 changes: 9 additions & 8 deletions homeassistant/components/sensor/tellduslive.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"""
import logging

from homeassistant.components.tellduslive import TelldusLiveEntity
from homeassistant.components import tellduslive
from homeassistant.components.tellduslive.entry import TelldusLiveEntity
from homeassistant.const import (
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_TEMPERATURE,
TEMP_CELSIUS)
Expand All @@ -27,8 +28,8 @@
SENSOR_TYPE_BAROMETRIC_PRESSURE = 'barpress'

SENSOR_TYPES = {
SENSOR_TYPE_TEMPERATURE: ['Temperature', TEMP_CELSIUS, None,
DEVICE_CLASS_TEMPERATURE],
SENSOR_TYPE_TEMPERATURE:
['Temperature', TEMP_CELSIUS, None, DEVICE_CLASS_TEMPERATURE],
SENSOR_TYPE_HUMIDITY: ['Humidity', '%', None, DEVICE_CLASS_HUMIDITY],
SENSOR_TYPE_RAINRATE: ['Rain rate', 'mm/h', 'mdi:water', None],
SENSOR_TYPE_RAINTOTAL: ['Rain total', 'mm', 'mdi:water', None],
Expand All @@ -39,7 +40,7 @@
SENSOR_TYPE_WATT: ['Power', 'W', '', None],
SENSOR_TYPE_LUMINANCE: ['Luminance', 'lx', None, DEVICE_CLASS_ILLUMINANCE],
SENSOR_TYPE_DEW_POINT:
['Dew Point', TEMP_CELSIUS, None, DEVICE_CLASS_TEMPERATURE],
['Dew Point', TEMP_CELSIUS, None, DEVICE_CLASS_TEMPERATURE],
SENSOR_TYPE_BAROMETRIC_PRESSURE: ['Barometric Pressure', 'kPa', '', None],
}

Expand All @@ -48,7 +49,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Tellstick sensors."""
if discovery_info is None:
return
add_entities(TelldusLiveSensor(hass, sensor) for sensor in discovery_info)
client = hass.data[tellduslive.DOMAIN]
add_entities(
TelldusLiveSensor(client, sensor) for sensor in discovery_info)


class TelldusLiveSensor(TelldusLiveEntity):
Expand Down Expand Up @@ -87,9 +90,7 @@ def _value_as_humidity(self):
@property
def name(self):
"""Return the name of the sensor."""
return '{} {}'.format(
super().name,
self.quantity_name or '')
return '{} {}'.format(super().name, self.quantity_name or '').strip()

@property
def state(self):
Expand Down
9 changes: 5 additions & 4 deletions homeassistant/components/switch/tellduslive.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"""
import logging

from homeassistant.components.tellduslive import TelldusLiveEntity
from homeassistant.components import tellduslive
from homeassistant.components.tellduslive.entry import TelldusLiveEntity
from homeassistant.helpers.entity import ToggleEntity

_LOGGER = logging.getLogger(__name__)
Expand All @@ -19,7 +20,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up Tellstick switches."""
if discovery_info is None:
return
add_entities(TelldusLiveSwitch(hass, switch) for switch in discovery_info)
client = hass.data[tellduslive.DOMAIN]
add_entities(
TelldusLiveSwitch(client, switch) for switch in discovery_info)


class TelldusLiveSwitch(TelldusLiveEntity, ToggleEntity):
Expand All @@ -33,9 +36,7 @@ def is_on(self):
def turn_on(self, **kwargs):
"""Turn the switch on."""
self.device.turn_on()
self.changed()

def turn_off(self, **kwargs):
"""Turn the switch off."""
self.device.turn_off()
self.changed()
Loading