Skip to content

Commit

Permalink
Tellduslive refactoring (#18780)
Browse files Browse the repository at this point in the history
* move component to a package

* move TelldusLiveEntry to separate file

* refactor

* move entities from a shared container
* using the dispatch helper instead for communication between component and platforms

* updated covereagerc and codeowners

* suggestions from MartinHjelmare

* don't make update async

* "Strip is good!"
  • Loading branch information
fredrike authored and MartinHjelmare committed Dec 4, 2018
1 parent a6511fc commit d6a4e10
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 153 deletions.
3 changes: 2 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,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 @@ -236,8 +236,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()
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

0 comments on commit d6a4e10

Please sign in to comment.