mirror of
https://github.com/home-assistant/core.git
synced 2025-07-11 23:37:18 +00:00
ZigBee: Ensure correct entity types are used for each component.
This commit is contained in:
parent
241a768983
commit
c17a4fca80
@ -3,6 +3,8 @@ homeassistant.components.binary_sensor.zigbee
|
|||||||
|
|
||||||
Contains functionality to use a ZigBee device as a binary sensor.
|
Contains functionality to use a ZigBee device as a binary sensor.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||||
from homeassistant.components.zigbee import (
|
from homeassistant.components.zigbee import (
|
||||||
ZigBeeDigitalIn, ZigBeeDigitalInConfig)
|
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.
|
Create and add an entity based on the configuration.
|
||||||
"""
|
"""
|
||||||
add_entities([
|
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
|
||||||
|
@ -3,6 +3,8 @@ homeassistant.components.light.zigbee
|
|||||||
|
|
||||||
Contains functionality to use a ZigBee device as a light.
|
Contains functionality to use a ZigBee device as a light.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from homeassistant.components.light import Light
|
||||||
from homeassistant.components.zigbee import (
|
from homeassistant.components.zigbee import (
|
||||||
ZigBeeDigitalOut, ZigBeeDigitalOutConfig)
|
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.
|
Create and add an entity based on the configuration.
|
||||||
"""
|
"""
|
||||||
add_entities([
|
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
|
||||||
|
@ -60,7 +60,8 @@ class ZigBeeTemperatureSensor(Entity):
|
|||||||
def update(self, *args):
|
def update(self, *args):
|
||||||
self._temp = zigbee.DEVICE.get_temperature(self._config.address)
|
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 = {
|
TYPE_CLASSES = {
|
||||||
"temperature": (ZigBeeTemperatureSensor, zigbee.ZigBeeConfig),
|
"temperature": (ZigBeeTemperatureSensor, zigbee.ZigBeeConfig),
|
||||||
"analog": (zigbee.ZigBeeAnalogIn, zigbee.ZigBeeAnalogInConfig)
|
"analog": (zigbee.ZigBeeAnalogIn, zigbee.ZigBeeAnalogInConfig)
|
||||||
|
@ -3,6 +3,8 @@ homeassistant.components.switch.zigbee
|
|||||||
|
|
||||||
Contains functionality to use a ZigBee device as a switch.
|
Contains functionality to use a ZigBee device as a switch.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from homeassistant.components.switch import SwitchDevice
|
||||||
from homeassistant.components.zigbee import (
|
from homeassistant.components.zigbee import (
|
||||||
ZigBeeDigitalOut, ZigBeeDigitalOutConfig)
|
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.
|
Create and add an entity based on the configuration.
|
||||||
"""
|
"""
|
||||||
add_entities([
|
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
|
||||||
|
@ -10,8 +10,8 @@ import logging
|
|||||||
from binascii import unhexlify
|
from binascii import unhexlify
|
||||||
|
|
||||||
from homeassistant.core import JobPriority
|
from homeassistant.core import JobPriority
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, STATE_ON, STATE_OFF
|
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||||
from homeassistant.helpers.entity import Entity, ToggleEntity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
|
|
||||||
DOMAIN = "zigbee"
|
DOMAIN = "zigbee"
|
||||||
@ -194,7 +194,7 @@ class ZigBeeAnalogInConfig(ZigBeePinConfig):
|
|||||||
|
|
||||||
class ZigBeeDigitalIn(Entity):
|
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):
|
def __init__(self, hass, config):
|
||||||
self._config = config
|
self._config = config
|
||||||
@ -211,12 +211,11 @@ class ZigBeeDigitalIn(Entity):
|
|||||||
def should_poll(self):
|
def should_poll(self):
|
||||||
return self._config.should_poll
|
return self._config.should_poll
|
||||||
|
|
||||||
@property
|
|
||||||
def state(self):
|
|
||||||
return STATE_ON if self.is_on else STATE_OFF
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
|
"""
|
||||||
|
Returns True if the Entity is on, else False.
|
||||||
|
"""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
@ -229,7 +228,7 @@ class ZigBeeDigitalIn(Entity):
|
|||||||
self._state = self._config.state2bool[pin_state]
|
self._state = self._config.state2bool[pin_state]
|
||||||
|
|
||||||
|
|
||||||
class ZigBeeDigitalOut(ZigBeeDigitalIn, ToggleEntity):
|
class ZigBeeDigitalOut(ZigBeeDigitalIn):
|
||||||
"""
|
"""
|
||||||
Adds functionality to ZigBeeDigitalIn to control an output.
|
Adds functionality to ZigBeeDigitalIn to control an output.
|
||||||
"""
|
"""
|
||||||
@ -243,15 +242,21 @@ class ZigBeeDigitalOut(ZigBeeDigitalIn, ToggleEntity):
|
|||||||
self.update_ha_state()
|
self.update_ha_state()
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
|
"""
|
||||||
|
Set the digital output to its 'on' state.
|
||||||
|
"""
|
||||||
self._set_state(True)
|
self._set_state(True)
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
|
"""
|
||||||
|
Set the digital output to its 'off' state.
|
||||||
|
"""
|
||||||
self._set_state(False)
|
self._set_state(False)
|
||||||
|
|
||||||
|
|
||||||
class ZigBeeAnalogIn(Entity):
|
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):
|
def __init__(self, hass, config):
|
||||||
self._config = config
|
self._config = config
|
||||||
|
Loading…
x
Reference in New Issue
Block a user