diff --git a/homeassistant/components/binary_sensor/mysensors.py b/homeassistant/components/binary_sensor/mysensors.py index 77b4432e0003f172693bf14226354e84b9a66769..8d1b9eb2ea7c654ae9bd72b4f9875ea66b94c7ca 100644 --- a/homeassistant/components/binary_sensor/mysensors.py +++ b/homeassistant/components/binary_sensor/mysensors.py @@ -6,11 +6,11 @@ https://home-assistant.io/components/binary_sensor.mysensors/ """ import logging -import homeassistant.components.mysensors as mysensors from homeassistant.const import ( ATTR_BATTERY_LEVEL, STATE_OFF, STATE_ON) from homeassistant.components.binary_sensor import ( BinarySensorDevice, SENSOR_CLASSES) +from homeassistant.loader import get_component _LOGGER = logging.getLogger(__name__) DEPENDENCIES = [] @@ -23,6 +23,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None): if discovery_info is None: return + mysensors = get_component('mysensors') + for gateway in mysensors.GATEWAYS.values(): # Define the S_TYPES and V_TYPES that the platform should handle as # states. Map them in a dict of lists. @@ -74,6 +76,7 @@ class MySensorsBinarySensor(BinarySensorDevice): child_type (str): Child type of child. battery_level (int): Node battery level. _values (dict): Child values. Non state values set as state attributes. + mysensors (module): Mysensors main component module. """ self.gateway = gateway self.node_id = node_id @@ -83,6 +86,7 @@ class MySensorsBinarySensor(BinarySensorDevice): self.child_type = child_type self.battery_level = 0 self._values = {} + self.mysensors = get_component('mysensors') @property def should_poll(self): @@ -98,9 +102,9 @@ class MySensorsBinarySensor(BinarySensorDevice): def device_state_attributes(self): """Return device specific state attributes.""" attr = { - mysensors.ATTR_PORT: self.gateway.port, - mysensors.ATTR_NODE_ID: self.node_id, - mysensors.ATTR_CHILD_ID: self.child_id, + self.mysensors.ATTR_PORT: self.gateway.port, + self.mysensors.ATTR_NODE_ID: self.node_id, + self.mysensors.ATTR_CHILD_ID: self.child_id, ATTR_BATTERY_LEVEL: self.battery_level, } diff --git a/homeassistant/components/light/mysensors.py b/homeassistant/components/light/mysensors.py index c0daca374cbca2cfd7dbef07c807f21393bef3f1..f4fd7bc3c7980a9411a3bad497e04b9669a1e7e0 100644 --- a/homeassistant/components/light/mysensors.py +++ b/homeassistant/components/light/mysensors.py @@ -6,10 +6,10 @@ https://home-assistant.io/components/light.mysensors/ """ import logging -import homeassistant.components.mysensors as mysensors from homeassistant.components.light import ( ATTR_BRIGHTNESS, ATTR_RGB_COLOR, Light) from homeassistant.const import ATTR_BATTERY_LEVEL, STATE_OFF, STATE_ON +from homeassistant.loader import get_component from homeassistant.util.color import rgb_hex_to_rgb_list _LOGGER = logging.getLogger(__name__) @@ -25,6 +25,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None): if discovery_info is None: return + mysensors = get_component('mysensors') + for gateway in mysensors.GATEWAYS.values(): # Define the S_TYPES and V_TYPES that the platform should handle as # states. Map them in a dict of lists. @@ -72,6 +74,7 @@ class MySensorsLight(Light): self._brightness = None self._rgb = None self._white = None + self.mysensors = get_component('mysensors') @property def should_poll(self): @@ -102,9 +105,9 @@ class MySensorsLight(Light): def device_state_attributes(self): """Return device specific state attributes.""" device_attr = { - mysensors.ATTR_PORT: self.gateway.port, - mysensors.ATTR_NODE_ID: self.node_id, - mysensors.ATTR_CHILD_ID: self.child_id, + self.mysensors.ATTR_PORT: self.gateway.port, + self.mysensors.ATTR_NODE_ID: self.node_id, + self.mysensors.ATTR_CHILD_ID: self.child_id, ATTR_BATTERY_LEVEL: self.battery_level, } for value_type, value in self._values.items(): diff --git a/homeassistant/components/sensor/mysensors.py b/homeassistant/components/sensor/mysensors.py index ffea48929881f9fefa095750f57b929ec43a9720..ee05b731268dd462821de43df4b94a8c1b1d03bb 100644 --- a/homeassistant/components/sensor/mysensors.py +++ b/homeassistant/components/sensor/mysensors.py @@ -6,10 +6,10 @@ https://home-assistant.io/components/sensor.mysensors/ """ import logging -import homeassistant.components.mysensors as mysensors from homeassistant.const import ( ATTR_BATTERY_LEVEL, STATE_OFF, STATE_ON, TEMP_CELCIUS, TEMP_FAHRENHEIT) from homeassistant.helpers.entity import Entity +from homeassistant.loader import get_component _LOGGER = logging.getLogger(__name__) DEPENDENCIES = [] @@ -22,6 +22,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None): if discovery_info is None: return + mysensors = get_component('mysensors') + for gateway in mysensors.GATEWAYS.values(): # Define the S_TYPES and V_TYPES that the platform should handle as # states. Map them in a dict of lists. @@ -77,7 +79,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class MySensorsSensor(Entity): """Represent the value of a MySensors child node.""" - # pylint: disable=too-many-arguments + # pylint: disable=too-many-arguments,too-many-instance-attributes def __init__( self, gateway, node_id, child_id, name, value_type, child_type): @@ -99,6 +101,7 @@ class MySensorsSensor(Entity): value_type (str): Value type of child. Value is entity state. battery_level (int): Node battery level. _values (dict): Child values. Non state values set as state attributes. + mysensors (module): Mysensors main component module. """ self.gateway = gateway self.node_id = node_id @@ -107,6 +110,7 @@ class MySensorsSensor(Entity): self.value_type = value_type self.battery_level = 0 self._values = {} + self.mysensors = get_component('mysensors') @property def should_poll(self): @@ -156,9 +160,9 @@ class MySensorsSensor(Entity): def device_state_attributes(self): """Return device specific state attributes.""" attr = { - mysensors.ATTR_PORT: self.gateway.port, - mysensors.ATTR_NODE_ID: self.node_id, - mysensors.ATTR_CHILD_ID: self.child_id, + self.mysensors.ATTR_PORT: self.gateway.port, + self.mysensors.ATTR_NODE_ID: self.node_id, + self.mysensors.ATTR_CHILD_ID: self.child_id, ATTR_BATTERY_LEVEL: self.battery_level, } diff --git a/homeassistant/components/switch/mysensors.py b/homeassistant/components/switch/mysensors.py index e0797e42c54272d7d8b3f460228721f205864fc1..9921ddb3602af1542314ed65e3675c6ca9c312ce 100644 --- a/homeassistant/components/switch/mysensors.py +++ b/homeassistant/components/switch/mysensors.py @@ -6,9 +6,9 @@ https://home-assistant.io/components/switch.mysensors/ """ import logging -import homeassistant.components.mysensors as mysensors from homeassistant.components.switch import SwitchDevice from homeassistant.const import ATTR_BATTERY_LEVEL, STATE_OFF, STATE_ON +from homeassistant.loader import get_component _LOGGER = logging.getLogger(__name__) DEPENDENCIES = [] @@ -21,6 +21,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None): if discovery_info is None: return + mysensors = get_component('mysensors') + for gateway in mysensors.GATEWAYS.values(): # Define the S_TYPES and V_TYPES that the platform should handle as # states. Map them in a dict of lists. @@ -50,7 +52,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class MySensorsSwitch(SwitchDevice): """Represent the value of a MySensors child node.""" - # pylint: disable=too-many-arguments + # pylint: disable=too-many-arguments,too-many-instance-attributes def __init__( self, gateway, node_id, child_id, name, value_type, child_type): @@ -72,6 +74,7 @@ class MySensorsSwitch(SwitchDevice): value_type (str): Value type of child. Value is entity state. battery_level (int): Node battery level. _values (dict): Child values. Non state values set as state attributes. + mysensors (module): Mysensors main component module. """ self.gateway = gateway self.node_id = node_id @@ -80,6 +83,7 @@ class MySensorsSwitch(SwitchDevice): self.value_type = value_type self.battery_level = 0 self._values = {} + self.mysensors = get_component('mysensors') @property def should_poll(self): @@ -95,9 +99,9 @@ class MySensorsSwitch(SwitchDevice): def device_state_attributes(self): """Return device specific state attributes.""" attr = { - mysensors.ATTR_PORT: self.gateway.port, - mysensors.ATTR_NODE_ID: self.node_id, - mysensors.ATTR_CHILD_ID: self.child_id, + self.mysensors.ATTR_PORT: self.gateway.port, + self.mysensors.ATTR_NODE_ID: self.node_id, + self.mysensors.ATTR_CHILD_ID: self.child_id, ATTR_BATTERY_LEVEL: self.battery_level, }