mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Merge pull request #1394 from MartinHjelmare/use-get_component-mysensors
Use get_component instead of importing component for mysensors
This commit is contained in:
commit
caa1b73035
@ -6,11 +6,11 @@ https://home-assistant.io/components/binary_sensor.mysensors/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import homeassistant.components.mysensors as mysensors
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_BATTERY_LEVEL, STATE_OFF, STATE_ON)
|
ATTR_BATTERY_LEVEL, STATE_OFF, STATE_ON)
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
BinarySensorDevice, SENSOR_CLASSES)
|
BinarySensorDevice, SENSOR_CLASSES)
|
||||||
|
from homeassistant.loader import get_component
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
DEPENDENCIES = []
|
DEPENDENCIES = []
|
||||||
@ -23,6 +23,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
mysensors = get_component('mysensors')
|
||||||
|
|
||||||
for gateway in mysensors.GATEWAYS.values():
|
for gateway in mysensors.GATEWAYS.values():
|
||||||
# Define the S_TYPES and V_TYPES that the platform should handle as
|
# Define the S_TYPES and V_TYPES that the platform should handle as
|
||||||
# states. Map them in a dict of lists.
|
# states. Map them in a dict of lists.
|
||||||
@ -74,6 +76,7 @@ class MySensorsBinarySensor(BinarySensorDevice):
|
|||||||
child_type (str): Child type of child.
|
child_type (str): Child type of child.
|
||||||
battery_level (int): Node battery level.
|
battery_level (int): Node battery level.
|
||||||
_values (dict): Child values. Non state values set as state attributes.
|
_values (dict): Child values. Non state values set as state attributes.
|
||||||
|
mysensors (module): Mysensors main component module.
|
||||||
"""
|
"""
|
||||||
self.gateway = gateway
|
self.gateway = gateway
|
||||||
self.node_id = node_id
|
self.node_id = node_id
|
||||||
@ -83,6 +86,7 @@ class MySensorsBinarySensor(BinarySensorDevice):
|
|||||||
self.child_type = child_type
|
self.child_type = child_type
|
||||||
self.battery_level = 0
|
self.battery_level = 0
|
||||||
self._values = {}
|
self._values = {}
|
||||||
|
self.mysensors = get_component('mysensors')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self):
|
||||||
@ -98,9 +102,9 @@ class MySensorsBinarySensor(BinarySensorDevice):
|
|||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Return device specific state attributes."""
|
"""Return device specific state attributes."""
|
||||||
attr = {
|
attr = {
|
||||||
mysensors.ATTR_PORT: self.gateway.port,
|
self.mysensors.ATTR_PORT: self.gateway.port,
|
||||||
mysensors.ATTR_NODE_ID: self.node_id,
|
self.mysensors.ATTR_NODE_ID: self.node_id,
|
||||||
mysensors.ATTR_CHILD_ID: self.child_id,
|
self.mysensors.ATTR_CHILD_ID: self.child_id,
|
||||||
ATTR_BATTERY_LEVEL: self.battery_level,
|
ATTR_BATTERY_LEVEL: self.battery_level,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,10 +6,10 @@ https://home-assistant.io/components/light.mysensors/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import homeassistant.components.mysensors as mysensors
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS, ATTR_RGB_COLOR, Light)
|
ATTR_BRIGHTNESS, ATTR_RGB_COLOR, Light)
|
||||||
from homeassistant.const import ATTR_BATTERY_LEVEL, STATE_OFF, STATE_ON
|
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
|
from homeassistant.util.color import rgb_hex_to_rgb_list
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -25,6 +25,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
mysensors = get_component('mysensors')
|
||||||
|
|
||||||
for gateway in mysensors.GATEWAYS.values():
|
for gateway in mysensors.GATEWAYS.values():
|
||||||
# Define the S_TYPES and V_TYPES that the platform should handle as
|
# Define the S_TYPES and V_TYPES that the platform should handle as
|
||||||
# states. Map them in a dict of lists.
|
# states. Map them in a dict of lists.
|
||||||
@ -72,6 +74,7 @@ class MySensorsLight(Light):
|
|||||||
self._brightness = None
|
self._brightness = None
|
||||||
self._rgb = None
|
self._rgb = None
|
||||||
self._white = None
|
self._white = None
|
||||||
|
self.mysensors = get_component('mysensors')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self):
|
||||||
@ -102,9 +105,9 @@ class MySensorsLight(Light):
|
|||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Return device specific state attributes."""
|
"""Return device specific state attributes."""
|
||||||
device_attr = {
|
device_attr = {
|
||||||
mysensors.ATTR_PORT: self.gateway.port,
|
self.mysensors.ATTR_PORT: self.gateway.port,
|
||||||
mysensors.ATTR_NODE_ID: self.node_id,
|
self.mysensors.ATTR_NODE_ID: self.node_id,
|
||||||
mysensors.ATTR_CHILD_ID: self.child_id,
|
self.mysensors.ATTR_CHILD_ID: self.child_id,
|
||||||
ATTR_BATTERY_LEVEL: self.battery_level,
|
ATTR_BATTERY_LEVEL: self.battery_level,
|
||||||
}
|
}
|
||||||
for value_type, value in self._values.items():
|
for value_type, value in self._values.items():
|
||||||
|
@ -6,10 +6,10 @@ https://home-assistant.io/components/sensor.mysensors/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import homeassistant.components.mysensors as mysensors
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_BATTERY_LEVEL, STATE_OFF, STATE_ON, TEMP_CELCIUS, TEMP_FAHRENHEIT)
|
ATTR_BATTERY_LEVEL, STATE_OFF, STATE_ON, TEMP_CELCIUS, TEMP_FAHRENHEIT)
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
from homeassistant.loader import get_component
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
DEPENDENCIES = []
|
DEPENDENCIES = []
|
||||||
@ -22,6 +22,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
mysensors = get_component('mysensors')
|
||||||
|
|
||||||
for gateway in mysensors.GATEWAYS.values():
|
for gateway in mysensors.GATEWAYS.values():
|
||||||
# Define the S_TYPES and V_TYPES that the platform should handle as
|
# Define the S_TYPES and V_TYPES that the platform should handle as
|
||||||
# states. Map them in a dict of lists.
|
# 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):
|
class MySensorsSensor(Entity):
|
||||||
"""Represent the value of a MySensors child node."""
|
"""Represent the value of a MySensors child node."""
|
||||||
|
|
||||||
# pylint: disable=too-many-arguments
|
# pylint: disable=too-many-arguments,too-many-instance-attributes
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, gateway, node_id, child_id, name, value_type, child_type):
|
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.
|
value_type (str): Value type of child. Value is entity state.
|
||||||
battery_level (int): Node battery level.
|
battery_level (int): Node battery level.
|
||||||
_values (dict): Child values. Non state values set as state attributes.
|
_values (dict): Child values. Non state values set as state attributes.
|
||||||
|
mysensors (module): Mysensors main component module.
|
||||||
"""
|
"""
|
||||||
self.gateway = gateway
|
self.gateway = gateway
|
||||||
self.node_id = node_id
|
self.node_id = node_id
|
||||||
@ -107,6 +110,7 @@ class MySensorsSensor(Entity):
|
|||||||
self.value_type = value_type
|
self.value_type = value_type
|
||||||
self.battery_level = 0
|
self.battery_level = 0
|
||||||
self._values = {}
|
self._values = {}
|
||||||
|
self.mysensors = get_component('mysensors')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self):
|
||||||
@ -156,9 +160,9 @@ class MySensorsSensor(Entity):
|
|||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Return device specific state attributes."""
|
"""Return device specific state attributes."""
|
||||||
attr = {
|
attr = {
|
||||||
mysensors.ATTR_PORT: self.gateway.port,
|
self.mysensors.ATTR_PORT: self.gateway.port,
|
||||||
mysensors.ATTR_NODE_ID: self.node_id,
|
self.mysensors.ATTR_NODE_ID: self.node_id,
|
||||||
mysensors.ATTR_CHILD_ID: self.child_id,
|
self.mysensors.ATTR_CHILD_ID: self.child_id,
|
||||||
ATTR_BATTERY_LEVEL: self.battery_level,
|
ATTR_BATTERY_LEVEL: self.battery_level,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,9 +6,9 @@ https://home-assistant.io/components/switch.mysensors/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import homeassistant.components.mysensors as mysensors
|
|
||||||
from homeassistant.components.switch import SwitchDevice
|
from homeassistant.components.switch import SwitchDevice
|
||||||
from homeassistant.const import ATTR_BATTERY_LEVEL, STATE_OFF, STATE_ON
|
from homeassistant.const import ATTR_BATTERY_LEVEL, STATE_OFF, STATE_ON
|
||||||
|
from homeassistant.loader import get_component
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
DEPENDENCIES = []
|
DEPENDENCIES = []
|
||||||
@ -21,6 +21,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
mysensors = get_component('mysensors')
|
||||||
|
|
||||||
for gateway in mysensors.GATEWAYS.values():
|
for gateway in mysensors.GATEWAYS.values():
|
||||||
# Define the S_TYPES and V_TYPES that the platform should handle as
|
# Define the S_TYPES and V_TYPES that the platform should handle as
|
||||||
# states. Map them in a dict of lists.
|
# 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):
|
class MySensorsSwitch(SwitchDevice):
|
||||||
"""Represent the value of a MySensors child node."""
|
"""Represent the value of a MySensors child node."""
|
||||||
|
|
||||||
# pylint: disable=too-many-arguments
|
# pylint: disable=too-many-arguments,too-many-instance-attributes
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, gateway, node_id, child_id, name, value_type, child_type):
|
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.
|
value_type (str): Value type of child. Value is entity state.
|
||||||
battery_level (int): Node battery level.
|
battery_level (int): Node battery level.
|
||||||
_values (dict): Child values. Non state values set as state attributes.
|
_values (dict): Child values. Non state values set as state attributes.
|
||||||
|
mysensors (module): Mysensors main component module.
|
||||||
"""
|
"""
|
||||||
self.gateway = gateway
|
self.gateway = gateway
|
||||||
self.node_id = node_id
|
self.node_id = node_id
|
||||||
@ -80,6 +83,7 @@ class MySensorsSwitch(SwitchDevice):
|
|||||||
self.value_type = value_type
|
self.value_type = value_type
|
||||||
self.battery_level = 0
|
self.battery_level = 0
|
||||||
self._values = {}
|
self._values = {}
|
||||||
|
self.mysensors = get_component('mysensors')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self):
|
||||||
@ -95,9 +99,9 @@ class MySensorsSwitch(SwitchDevice):
|
|||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Return device specific state attributes."""
|
"""Return device specific state attributes."""
|
||||||
attr = {
|
attr = {
|
||||||
mysensors.ATTR_PORT: self.gateway.port,
|
self.mysensors.ATTR_PORT: self.gateway.port,
|
||||||
mysensors.ATTR_NODE_ID: self.node_id,
|
self.mysensors.ATTR_NODE_ID: self.node_id,
|
||||||
mysensors.ATTR_CHILD_ID: self.child_id,
|
self.mysensors.ATTR_CHILD_ID: self.child_id,
|
||||||
ATTR_BATTERY_LEVEL: self.battery_level,
|
ATTR_BATTERY_LEVEL: self.battery_level,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user