ZigBee: Ensure correct entity types are used for each component.

This commit is contained in:
Flyte 2016-01-29 12:00:53 +00:00
parent 241a768983
commit c17a4fca80
5 changed files with 48 additions and 13 deletions

View file

@ -3,6 +3,8 @@ homeassistant.components.binary_sensor.zigbee
Contains functionality to use a ZigBee device as a binary sensor.
"""
from homeassistant.components.binary_sensor import BinarySensorDevice
from homeassistant.components.zigbee import (
ZigBeeDigitalIn, ZigBeeDigitalInConfig)
@ -15,5 +17,13 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
Create and add an entity based on the configuration.
"""
add_entities([
ZigBeeDigitalIn(hass, ZigBeeDigitalInConfig(config))
ZigBeeBinarySensor(hass, ZigBeeDigitalInConfig(config))
])
class ZigBeeBinarySensor(ZigBeeDigitalIn, BinarySensorDevice):
"""
Use multiple inheritance to turn a ZigBeeDigitalIn into a
BinarySensorDevice.
"""
pass

View file

@ -3,6 +3,8 @@ homeassistant.components.light.zigbee
Contains functionality to use a ZigBee device as a light.
"""
from homeassistant.components.light import Light
from homeassistant.components.zigbee import (
ZigBeeDigitalOut, ZigBeeDigitalOutConfig)
@ -15,5 +17,13 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
Create and add an entity based on the configuration.
"""
add_entities([
ZigBeeDigitalOut(hass, ZigBeeDigitalOutConfig(config))
ZigBeeLight(hass, ZigBeeDigitalOutConfig(config))
])
class ZigBeeLight(ZigBeeDigitalOut, Light):
"""
Use multiple inheritance to turn an instance of ZigBeeDigitalOut into a
Light.
"""
pass

View file

@ -60,7 +60,8 @@ class ZigBeeTemperatureSensor(Entity):
def update(self, *args):
self._temp = zigbee.DEVICE.get_temperature(self._config.address)
# This must be below the ZigBeeTemperatureSensor which it references.
# This must be below the classes to which it refers.
TYPE_CLASSES = {
"temperature": (ZigBeeTemperatureSensor, zigbee.ZigBeeConfig),
"analog": (zigbee.ZigBeeAnalogIn, zigbee.ZigBeeAnalogInConfig)

View file

@ -3,6 +3,8 @@ homeassistant.components.switch.zigbee
Contains functionality to use a ZigBee device as a switch.
"""
from homeassistant.components.switch import SwitchDevice
from homeassistant.components.zigbee import (
ZigBeeDigitalOut, ZigBeeDigitalOutConfig)
@ -15,5 +17,12 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
Create and add an entity based on the configuration.
"""
add_entities([
ZigBeeDigitalOut(hass, ZigBeeDigitalOutConfig(config))
ZigBeeSwitch(hass, ZigBeeDigitalOutConfig(config))
])
class ZigBeeSwitch(ZigBeeDigitalOut, SwitchDevice):
"""
Use multiple inheritance to turn a ZigBeeDigitalOut into a SwitchDevice.
"""
pass

View file

@ -10,8 +10,8 @@ import logging
from binascii import unhexlify
from homeassistant.core import JobPriority
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, STATE_ON, STATE_OFF
from homeassistant.helpers.entity import Entity, ToggleEntity
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
from homeassistant.helpers.entity import Entity
DOMAIN = "zigbee"
@ -194,7 +194,7 @@ class ZigBeeAnalogInConfig(ZigBeePinConfig):
class ZigBeeDigitalIn(Entity):
"""
ToggleEntity to represent a GPIO pin configured as a digital input.
Represents a GPIO pin configured as a digital input.
"""
def __init__(self, hass, config):
self._config = config
@ -211,12 +211,11 @@ class ZigBeeDigitalIn(Entity):
def should_poll(self):
return self._config.should_poll
@property
def state(self):
return STATE_ON if self.is_on else STATE_OFF
@property
def is_on(self):
"""
Returns True if the Entity is on, else False.
"""
return self._state
def update(self):
@ -229,7 +228,7 @@ class ZigBeeDigitalIn(Entity):
self._state = self._config.state2bool[pin_state]
class ZigBeeDigitalOut(ZigBeeDigitalIn, ToggleEntity):
class ZigBeeDigitalOut(ZigBeeDigitalIn):
"""
Adds functionality to ZigBeeDigitalIn to control an output.
"""
@ -243,15 +242,21 @@ class ZigBeeDigitalOut(ZigBeeDigitalIn, ToggleEntity):
self.update_ha_state()
def turn_on(self, **kwargs):
"""
Set the digital output to its 'on' state.
"""
self._set_state(True)
def turn_off(self, **kwargs):
"""
Set the digital output to its 'off' state.
"""
self._set_state(False)
class ZigBeeAnalogIn(Entity):
"""
Entity to represent a GPIO pin configured as an analog input.
Represents a GPIO pin configured as an analog input.
"""
def __init__(self, hass, config):
self._config = config