Rename zigbee to xbee (#35613)

This commit is contained in:
Franck Nijhof 2020-05-14 12:19:59 +02:00 committed by GitHub
parent 55b444cccf
commit c67d035366
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 62 additions and 72 deletions

View File

@ -914,7 +914,7 @@ omit =
homeassistant/components/zha/light.py homeassistant/components/zha/light.py
homeassistant/components/zha/sensor.py homeassistant/components/zha/sensor.py
homeassistant/components/zhong_hong/climate.py homeassistant/components/zhong_hong/climate.py
homeassistant/components/zigbee/* homeassistant/components/xbee/*
homeassistant/components/ziggo_mediabox_xl/media_player.py homeassistant/components/ziggo_mediabox_xl/media_player.py
homeassistant/components/zoneminder/* homeassistant/components/zoneminder/*
homeassistant/components/supla/* homeassistant/components/supla/*

View File

@ -1,4 +1,4 @@
"""Support for Zigbee devices.""" """Support for XBee Zigbee devices."""
from binascii import hexlify, unhexlify from binascii import hexlify, unhexlify
import logging import logging
@ -23,9 +23,9 @@ from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
DOMAIN = "zigbee" DOMAIN = "xbee"
SIGNAL_ZIGBEE_FRAME_RECEIVED = "zigbee_frame_received" SIGNAL_XBEE_FRAME_RECEIVED = "xbee_frame_received"
CONF_BAUD = "baud" CONF_BAUD = "baud"
@ -58,28 +58,28 @@ PLATFORM_SCHEMA = vol.Schema(
def setup(hass, config): def setup(hass, config):
"""Set up the connection to the Zigbee device.""" """Set up the connection to the XBee Zigbee device."""
usb_device = config[DOMAIN].get(CONF_DEVICE, DEFAULT_DEVICE) usb_device = config[DOMAIN].get(CONF_DEVICE, DEFAULT_DEVICE)
baud = int(config[DOMAIN].get(CONF_BAUD, DEFAULT_BAUD)) baud = int(config[DOMAIN].get(CONF_BAUD, DEFAULT_BAUD))
try: try:
ser = Serial(usb_device, baud) ser = Serial(usb_device, baud)
except SerialException as exc: except SerialException as exc:
_LOGGER.exception("Unable to open serial port for Zigbee: %s", exc) _LOGGER.exception("Unable to open serial port for XBee: %s", exc)
return False return False
zigbee_device = ZigBee(ser) zigbee_device = ZigBee(ser)
def close_serial_port(*args): def close_serial_port(*args):
"""Close the serial port we're using to communicate with the Zigbee.""" """Close the serial port we're using to communicate with the XBee."""
zigbee_device.zb.serial.close() zigbee_device.zb.serial.close()
def _frame_received(frame): def _frame_received(frame):
"""Run when a Zigbee frame is received. """Run when a XBee Zigbee frame is received.
Pickles the frame, then encodes it into base64 since it contains Pickles the frame, then encodes it into base64 since it contains
non JSON serializable binary. non JSON serializable binary.
""" """
dispatcher_send(hass, SIGNAL_ZIGBEE_FRAME_RECEIVED, frame) dispatcher_send(hass, SIGNAL_XBEE_FRAME_RECEIVED, frame)
hass.data[DOMAIN] = zigbee_device hass.data[DOMAIN] = zigbee_device
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, close_serial_port) hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, close_serial_port)
@ -92,12 +92,10 @@ def frame_is_relevant(entity, frame):
"""Test whether the frame is relevant to the entity.""" """Test whether the frame is relevant to the entity."""
if frame.get("source_addr_long") != entity.config.address: if frame.get("source_addr_long") != entity.config.address:
return False return False
if "samples" not in frame: return "samples" in frame
return False
return True
class ZigBeeConfig: class XBeeConfig:
"""Handle the fetching of configuration from the config file.""" """Handle the fetching of configuration from the config file."""
def __init__(self, config): def __init__(self, config):
@ -115,7 +113,7 @@ class ZigBeeConfig:
"""Return the address of the device. """Return the address of the device.
If an address has been provided, unhexlify it, otherwise return None If an address has been provided, unhexlify it, otherwise return None
as we're talking to our local Zigbee device. as we're talking to our local XBee device.
""" """
address = self._config.get("address") address = self._config.get("address")
if address is not None: if address is not None:
@ -128,7 +126,7 @@ class ZigBeeConfig:
return self._should_poll return self._should_poll
class ZigBeePinConfig(ZigBeeConfig): class XBeePinConfig(XBeeConfig):
"""Handle the fetching of configuration from the configuration file.""" """Handle the fetching of configuration from the configuration file."""
@property @property
@ -137,11 +135,11 @@ class ZigBeePinConfig(ZigBeeConfig):
return self._config["pin"] return self._config["pin"]
class ZigBeeDigitalInConfig(ZigBeePinConfig): class XBeeDigitalInConfig(XBeePinConfig):
"""A subclass of ZigBeePinConfig.""" """A subclass of XBeePinConfig."""
def __init__(self, config): def __init__(self, config):
"""Initialise the Zigbee Digital input config.""" """Initialise the XBee Zigbee Digital input config."""
super().__init__(config) super().__init__(config)
self._bool2state, self._state2bool = self.boolean_maps self._bool2state, self._state2bool = self.boolean_maps
@ -177,15 +175,15 @@ class ZigBeeDigitalInConfig(ZigBeePinConfig):
return self._state2bool return self._state2bool
class ZigBeeDigitalOutConfig(ZigBeePinConfig): class XBeeDigitalOutConfig(XBeePinConfig):
"""A subclass of ZigBeePinConfig. """A subclass of XBeePinConfig.
Set _should_poll to default as False instead of True. The value will Set _should_poll to default as False instead of True. The value will
still be overridden by the presence of a 'poll' config entry. still be overridden by the presence of a 'poll' config entry.
""" """
def __init__(self, config): def __init__(self, config):
"""Initialize the Zigbee Digital out.""" """Initialize the XBee Zigbee Digital out."""
super().__init__(config) super().__init__(config)
self._bool2state, self._state2bool = self.boolean_maps self._bool2state, self._state2bool = self.boolean_maps
self._should_poll = config.get("poll", False) self._should_poll = config.get("poll", False)
@ -227,8 +225,8 @@ class ZigBeeDigitalOutConfig(ZigBeePinConfig):
return self._state2bool return self._state2bool
class ZigBeeAnalogInConfig(ZigBeePinConfig): class XBeeAnalogInConfig(XBeePinConfig):
"""Representation of a Zigbee GPIO pin set to analog in.""" """Representation of a XBee Zigbee GPIO pin set to analog in."""
@property @property
def max_voltage(self): def max_voltage(self):
@ -236,7 +234,7 @@ class ZigBeeAnalogInConfig(ZigBeePinConfig):
return float(self._config.get("max_volts", DEFAULT_ADC_MAX_VOLTS)) return float(self._config.get("max_volts", DEFAULT_ADC_MAX_VOLTS))
class ZigBeeDigitalIn(Entity): class XBeeDigitalIn(Entity):
"""Representation of a GPIO pin configured as a digital input.""" """Representation of a GPIO pin configured as a digital input."""
def __init__(self, config, device): def __init__(self, config, device):
@ -268,7 +266,7 @@ class ZigBeeDigitalIn(Entity):
] ]
self.schedule_update_ha_state() self.schedule_update_ha_state()
async_dispatcher_connect(self.hass, SIGNAL_ZIGBEE_FRAME_RECEIVED, handle_frame) async_dispatcher_connect(self.hass, SIGNAL_XBEE_FRAME_RECEIVED, handle_frame)
@property @property
def name(self): def name(self):
@ -316,11 +314,11 @@ class ZigBeeDigitalIn(Entity):
self._state = self._config.state2bool[sample[pin_name]] self._state = self._config.state2bool[sample[pin_name]]
class ZigBeeDigitalOut(ZigBeeDigitalIn): class XBeeDigitalOut(XBeeDigitalIn):
"""Representation of a GPIO pin configured as a digital input.""" """Representation of a GPIO pin configured as a digital input."""
def _set_state(self, state): def _set_state(self, state):
"""Initialize the Zigbee digital out device.""" """Initialize the XBee Zigbee digital out device."""
try: try:
self._device.set_gpio_pin( self._device.set_gpio_pin(
self._config.pin, self._config.bool2state[state], self._config.address self._config.pin, self._config.bool2state[state], self._config.address
@ -333,7 +331,7 @@ class ZigBeeDigitalOut(ZigBeeDigitalIn):
) )
return return
except ZigBeeException as exc: except ZigBeeException as exc:
_LOGGER.exception("Unable to set digital pin on Zigbee device: %s", exc) _LOGGER.exception("Unable to set digital pin on XBee device: %s", exc)
return return
self._state = state self._state = state
if not self.should_poll: if not self.should_poll:
@ -348,7 +346,7 @@ class ZigBeeDigitalOut(ZigBeeDigitalIn):
self._set_state(False) self._set_state(False)
def update(self): def update(self):
"""Ask the Zigbee device what its output is set to.""" """Ask the XBee device what its output is set to."""
try: try:
pin_state = self._device.get_gpio_pin( pin_state = self._device.get_gpio_pin(
self._config.pin, self._config.address self._config.pin, self._config.address
@ -362,17 +360,17 @@ class ZigBeeDigitalOut(ZigBeeDigitalIn):
return return
except ZigBeeException as exc: except ZigBeeException as exc:
_LOGGER.exception( _LOGGER.exception(
"Unable to get output pin status from Zigbee device: %s", exc "Unable to get output pin status from XBee device: %s", exc
) )
return return
self._state = self._config.state2bool[pin_state] self._state = self._config.state2bool[pin_state]
class ZigBeeAnalogIn(Entity): class XBeeAnalogIn(Entity):
"""Representation of a GPIO pin configured as an analog input.""" """Representation of a GPIO pin configured as an analog input."""
def __init__(self, config, device): def __init__(self, config, device):
"""Initialize the ZigBee analog in device.""" """Initialize the XBee analog in device."""
self._config = config self._config = config
self._device = device self._device = device
self._value = None self._value = None
@ -398,7 +396,7 @@ class ZigBeeAnalogIn(Entity):
) )
self.schedule_update_ha_state() self.schedule_update_ha_state()
async_dispatcher_connect(self.hass, SIGNAL_ZIGBEE_FRAME_RECEIVED, handle_frame) async_dispatcher_connect(self.hass, SIGNAL_XBEE_FRAME_RECEIVED, handle_frame)
@property @property
def name(self): def name(self):

View File

@ -3,7 +3,7 @@ import voluptuous as vol
from homeassistant.components.binary_sensor import BinarySensorEntity from homeassistant.components.binary_sensor import BinarySensorEntity
from . import DOMAIN, PLATFORM_SCHEMA, ZigBeeDigitalIn, ZigBeeDigitalInConfig from . import DOMAIN, PLATFORM_SCHEMA, XBeeDigitalIn, XBeeDigitalInConfig
CONF_ON_STATE = "on_state" CONF_ON_STATE = "on_state"
@ -14,12 +14,10 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({vol.Optional(CONF_ON_STATE): vol.In(ST
def setup_platform(hass, config, add_entities, discovery_info=None): def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Zigbee binary sensor platform.""" """Set up the XBee Zigbee binary sensor platform."""
zigbee_device = hass.data[DOMAIN] zigbee_device = hass.data[DOMAIN]
add_entities( add_entities([XBeeBinarySensor(XBeeDigitalInConfig(config), zigbee_device)], True)
[ZigBeeBinarySensor(ZigBeeDigitalInConfig(config), zigbee_device)], True
)
class ZigBeeBinarySensor(ZigBeeDigitalIn, BinarySensorEntity): class XBeeBinarySensor(XBeeDigitalIn, BinarySensorEntity):
"""Use ZigBeeDigitalIn as binary sensor.""" """Use XBeeDigitalIn as binary sensor."""

View File

@ -1,9 +1,9 @@
"""Support for Zigbee lights.""" """Support for XBee Zigbee lights."""
import voluptuous as vol import voluptuous as vol
from homeassistant.components.light import LightEntity from homeassistant.components.light import LightEntity
from . import DOMAIN, PLATFORM_SCHEMA, ZigBeeDigitalOut, ZigBeeDigitalOutConfig from . import DOMAIN, PLATFORM_SCHEMA, XBeeDigitalOut, XBeeDigitalOutConfig
CONF_ON_STATE = "on_state" CONF_ON_STATE = "on_state"
@ -18,8 +18,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
def setup_platform(hass, config, add_entities, discovery_info=None): 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."""
zigbee_device = hass.data[DOMAIN] zigbee_device = hass.data[DOMAIN]
add_entities([ZigBeeLight(ZigBeeDigitalOutConfig(config), zigbee_device)]) add_entities([XBeeLight(XBeeDigitalOutConfig(config), zigbee_device)])
class ZigBeeLight(ZigBeeDigitalOut, LightEntity): class XBeeLight(XBeeDigitalOut, LightEntity):
"""Use ZigBeeDigitalOut as light.""" """Use XBeeDigitalOut as light."""

View File

@ -0,0 +1,7 @@
{
"domain": "xbee",
"name": "XBee",
"documentation": "https://www.home-assistant.io/integrations/xbee",
"requirements": ["xbee-helper==0.0.7"],
"codeowners": []
}

View File

@ -1,4 +1,4 @@
"""Support for Zigbee sensors.""" """Support for XBee Zigbee sensors."""
from binascii import hexlify from binascii import hexlify
import logging import logging
@ -8,13 +8,7 @@ from xbee_helper.exceptions import ZigBeeException, ZigBeeTxFailure
from homeassistant.const import TEMP_CELSIUS from homeassistant.const import TEMP_CELSIUS
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from . import ( from . import DOMAIN, PLATFORM_SCHEMA, XBeeAnalogIn, XBeeAnalogInConfig, XBeeConfig
DOMAIN,
PLATFORM_SCHEMA,
ZigBeeAnalogIn,
ZigBeeAnalogInConfig,
ZigBeeConfig,
)
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -33,7 +27,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
def setup_platform(hass, config, add_entities, discovery_info=None): def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Zigbee platform. """Set up the XBee Zigbee platform.
Uses the 'type' config value to work out which type of Zigbee sensor we're Uses the 'type' config value to work out which type of Zigbee sensor we're
dealing with and instantiates the relevant classes to handle it. dealing with and instantiates the relevant classes to handle it.
@ -44,13 +38,13 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
try: try:
sensor_class, config_class = TYPE_CLASSES[typ] sensor_class, config_class = TYPE_CLASSES[typ]
except KeyError: except KeyError:
_LOGGER.exception("Unknown Zigbee sensor type: %s", typ) _LOGGER.exception("Unknown XBee Zigbee sensor type: %s", typ)
return return
add_entities([sensor_class(config_class(config), zigbee_device)], True) add_entities([sensor_class(config_class(config), zigbee_device)], True)
class ZigBeeTemperatureSensor(Entity): class XBeeTemperatureSensor(Entity):
"""Representation of XBee Pro temperature sensor.""" """Representation of XBee Pro temperature sensor."""
def __init__(self, config, device): def __init__(self, config, device):
@ -90,6 +84,6 @@ class ZigBeeTemperatureSensor(Entity):
# This must be below the classes to which it refers. # This must be below the classes to which it refers.
TYPE_CLASSES = { TYPE_CLASSES = {
"temperature": (ZigBeeTemperatureSensor, ZigBeeConfig), "temperature": (XBeeTemperatureSensor, XBeeConfig),
"analog": (ZigBeeAnalogIn, ZigBeeAnalogInConfig), "analog": (XBeeAnalogIn, XBeeAnalogInConfig),
} }

View File

@ -1,9 +1,9 @@
"""Support for Zigbee switches.""" """Support for XBee Zigbee switches."""
import voluptuous as vol import voluptuous as vol
from homeassistant.components.switch import SwitchEntity from homeassistant.components.switch import SwitchEntity
from . import DOMAIN, PLATFORM_SCHEMA, ZigBeeDigitalOut, ZigBeeDigitalOutConfig from . import DOMAIN, PLATFORM_SCHEMA, XBeeDigitalOut, XBeeDigitalOutConfig
CONF_ON_STATE = "on_state" CONF_ON_STATE = "on_state"
@ -15,10 +15,10 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({vol.Optional(CONF_ON_STATE): vol.In(ST
def setup_platform(hass, config, add_entities, discovery_info=None): def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Zigbee switch platform.""" """Set up the XBee Zigbee switch platform."""
zigbee_device = hass.data[DOMAIN] zigbee_device = hass.data[DOMAIN]
add_entities([ZigBeeSwitch(ZigBeeDigitalOutConfig(config), zigbee_device)]) add_entities([XBeeSwitch(XBeeDigitalOutConfig(config), zigbee_device)])
class ZigBeeSwitch(ZigBeeDigitalOut, SwitchEntity): class XBeeSwitch(XBeeDigitalOut, SwitchEntity):
"""Representation of a Zigbee Digital Out device.""" """Representation of a XBee Zigbee Digital Out device."""

View File

@ -1,7 +0,0 @@
{
"domain": "zigbee",
"name": "Zigbee",
"documentation": "https://www.home-assistant.io/integrations/zigbee",
"requirements": ["xbee-helper==0.0.7"],
"codeowners": []
}

View File

@ -2194,7 +2194,7 @@ wled==0.3.0
# homeassistant.components.wunderlist # homeassistant.components.wunderlist
wunderpy2==0.1.6 wunderpy2==0.1.6
# homeassistant.components.zigbee # homeassistant.components.xbee
xbee-helper==0.0.7 xbee-helper==0.0.7
# homeassistant.components.xbox_live # homeassistant.components.xbox_live