Use get_component instead of importing component

This commit is contained in:
MartinHjelmare 2016-02-25 00:24:31 +01:00
parent c2729211ad
commit 2790ee0b02
4 changed files with 33 additions and 18 deletions

View file

@ -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,
}