Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# load the ZHA API
async_load_api(hass)
# create zigpy device
await async_init_zigpy_device(
hass,
[general.OnOff.cluster_id, general.Basic.cluster_id],
[],
None,
zha_gateway,
)
await async_init_zigpy_device(
hass,
[general.OnOff.cluster_id, general.Basic.cluster_id, general.Groups.cluster_id],
[],
zigpy.profiles.zha.DeviceType.ON_OFF_LIGHT,
zha_gateway,
manufacturer="FakeGroupManufacturer",
model="FakeGroupModel",
ieee="01:2d:6f:00:0a:90:69:e8",
)
# load up switch domain
await hass.config_entries.async_forward_entry_setup(config_entry, DOMAIN)
await hass.async_block_till_done()
await hass.config_entries.async_forward_entry_setup(config_entry, light_domain)
await hass.async_block_till_done()
return await hass_ws_client(hass)
@registries.ZIGBEE_CHANNEL_REGISTRY.register(general.DeviceTemperature.cluster_id)
class DeviceTemperature(ZigbeeChannel):
"""Device Temperature channel."""
pass
@registries.ZIGBEE_CHANNEL_REGISTRY.register(general.GreenPowerProxy.cluster_id)
class GreenPowerProxy(ZigbeeChannel):
"""Green Power Proxy channel."""
pass
@registries.ZIGBEE_CHANNEL_REGISTRY.register(general.Groups.cluster_id)
class Groups(ZigbeeChannel):
"""Groups channel."""
pass
@registries.ZIGBEE_CHANNEL_REGISTRY.register(general.Identify.cluster_id)
class Identify(ZigbeeChannel):
"""Identify channel."""
pass
@registries.BINDABLE_CLUSTERS.register(general.LevelControl.cluster_id)
@registries.EVENT_RELAY_CLUSTERS.register(general.LevelControl.cluster_id)
@registries.LIGHT_CLUSTERS.register(general.LevelControl.cluster_id)
def populate_listener_registry():
"""Populate the listener registry."""
from zigpy import zcl
LISTENER_REGISTRY.update({
zcl.clusters.general.Alarms.cluster_id: ClusterListener,
zcl.clusters.general.Commissioning.cluster_id: ClusterListener,
zcl.clusters.general.Identify.cluster_id: ClusterListener,
zcl.clusters.general.Groups.cluster_id: ClusterListener,
zcl.clusters.general.Scenes.cluster_id: ClusterListener,
zcl.clusters.general.Partition.cluster_id: ClusterListener,
zcl.clusters.general.Ota.cluster_id: ClusterListener,
zcl.clusters.general.PowerProfile.cluster_id: ClusterListener,
zcl.clusters.general.ApplianceControl.cluster_id: ClusterListener,
zcl.clusters.general.PollControl.cluster_id: ClusterListener,
zcl.clusters.general.GreenPowerProxy.cluster_id: ClusterListener,
zcl.clusters.general.OnOffConfiguration.cluster_id: ClusterListener,
zcl.clusters.general.OnOff.cluster_id: OnOffListener,
zcl.clusters.general.LevelControl.cluster_id: LevelListener,
zcl.clusters.lighting.Color.cluster_id: ColorListener,
zcl.clusters.homeautomation.ElectricalMeasurement.cluster_id:
ActivePowerListener,
def populate_channel_registry():
"""Populate the channel registry."""
from zigpy import zcl
ZIGBEE_CHANNEL_REGISTRY.update(
{
zcl.clusters.closures.DoorLock.cluster_id: DoorLockChannel,
zcl.clusters.general.Alarms.cluster_id: ZigbeeChannel,
zcl.clusters.general.ApplianceControl.cluster_id: ZigbeeChannel,
zcl.clusters.general.Basic.cluster_id: BasicChannel,
zcl.clusters.general.Commissioning.cluster_id: ZigbeeChannel,
zcl.clusters.general.GreenPowerProxy.cluster_id: ZigbeeChannel,
zcl.clusters.general.Groups.cluster_id: ZigbeeChannel,
zcl.clusters.general.Identify.cluster_id: ZigbeeChannel,
zcl.clusters.general.LevelControl.cluster_id: LevelControlChannel,
zcl.clusters.general.OnOff.cluster_id: OnOffChannel,
zcl.clusters.general.OnOffConfiguration.cluster_id: ZigbeeChannel,
zcl.clusters.general.Ota.cluster_id: ZigbeeChannel,
zcl.clusters.general.Partition.cluster_id: ZigbeeChannel,
zcl.clusters.general.PollControl.cluster_id: ZigbeeChannel,
zcl.clusters.general.PowerConfiguration.cluster_id: PowerConfigurationChannel,
zcl.clusters.general.PowerProfile.cluster_id: ZigbeeChannel,
zcl.clusters.general.Scenes.cluster_id: ZigbeeChannel,
zcl.clusters.homeautomation.ElectricalMeasurement.cluster_id: ElectricalMeasurementChannel,
zcl.clusters.hvac.Fan.cluster_id: FanChannel,
zcl.clusters.lighting.Color.cluster_id: ColorChannel,
zcl.clusters.lightlink.LightLink.cluster_id: ZigbeeChannel,
zcl.clusters.security.IasZone.cluster_id: IASZoneChannel,
}
zigpy.profiles.zll.DeviceType.DIMMABLE_PLUGIN_UNIT: LIGHT,
zigpy.profiles.zll.DeviceType.EXTENDED_COLOR_LIGHT: LIGHT,
zigpy.profiles.zll.DeviceType.ON_OFF_LIGHT: LIGHT,
zigpy.profiles.zll.DeviceType.ON_OFF_PLUGIN_UNIT: SWITCH,
}
)
SINGLE_INPUT_CLUSTER_DEVICE_CLASS.update(
{
# this works for now but if we hit conflicts we can break it out to
# a different dict that is keyed by manufacturer
SMARTTHINGS_ACCELERATION_CLUSTER: BINARY_SENSOR,
SMARTTHINGS_HUMIDITY_CLUSTER: SENSOR,
zcl.clusters.closures.DoorLock: LOCK,
zcl.clusters.general.AnalogInput.cluster_id: SENSOR,
zcl.clusters.general.MultistateInput.cluster_id: SENSOR,
zcl.clusters.general.OnOff: SWITCH,
zcl.clusters.general.PowerConfiguration: SENSOR,
zcl.clusters.homeautomation.ElectricalMeasurement: SENSOR,
zcl.clusters.hvac.Fan: FAN,
zcl.clusters.measurement.IlluminanceMeasurement: SENSOR,
zcl.clusters.measurement.OccupancySensing: BINARY_SENSOR,
zcl.clusters.measurement.PressureMeasurement: SENSOR,
zcl.clusters.measurement.RelativeHumidity: SENSOR,
zcl.clusters.measurement.TemperatureMeasurement: SENSOR,
zcl.clusters.security.IasZone: BINARY_SENSOR,
zcl.clusters.smartenergy.Metering: SENSOR,
}
)
SINGLE_OUTPUT_CLUSTER_DEVICE_CLASS.update(
{zcl.clusters.general.OnOff: BINARY_SENSOR}
@registries.ZIGBEE_CHANNEL_REGISTRY.register(general.GreenPowerProxy.cluster_id)
class GreenPowerProxy(ZigbeeChannel):
"""Green Power Proxy channel."""
pass
@registries.ZIGBEE_CHANNEL_REGISTRY.register(general.Groups.cluster_id)
class Groups(ZigbeeChannel):
"""Groups channel."""
pass
@registries.ZIGBEE_CHANNEL_REGISTRY.register(general.Identify.cluster_id)
class Identify(ZigbeeChannel):
"""Identify channel."""
pass
@registries.BINDABLE_CLUSTERS.register(general.LevelControl.cluster_id)
@registries.EVENT_RELAY_CLUSTERS.register(general.LevelControl.cluster_id)
@registries.LIGHT_CLUSTERS.register(general.LevelControl.cluster_id)
@registries.ZIGBEE_CHANNEL_REGISTRY.register(general.LevelControl.cluster_id)
class LevelControlChannel(ZigbeeChannel):
"""Channel for the LevelControl Zigbee cluster."""
CURRENT_LEVEL = 0
REPORT_CONFIG = ({"attr": "current_level", "config": REPORT_CONFIG_ASAP},)
if attrid == self.CURRENT_LEVEL:
self.dispatch_level_change(SIGNAL_SET_LEVEL, value)
def dispatch_level_change(self, command, level):
"""Dispatch level change."""
async_dispatcher_send(
self._zha_device.hass, f"{self.unique_id}_{command}", level
)
async def async_initialize(self, from_cache):
"""Initialize channel."""
await self.get_attribute_value(self.CURRENT_LEVEL, from_cache=from_cache)
await super().async_initialize(from_cache)
@registries.ZIGBEE_CHANNEL_REGISTRY.register(general.MultistateInput.cluster_id)
class MultistateInput(AttributeListeningChannel):
"""Multistate Input channel."""
REPORT_CONFIG = [{"attr": "present_value", "config": REPORT_CONFIG_DEFAULT}]
@registries.ZIGBEE_CHANNEL_REGISTRY.register(general.MultistateOutput.cluster_id)
class MultistateOutput(AttributeListeningChannel):
"""Multistate Output channel."""
REPORT_CONFIG = [{"attr": "present_value", "config": REPORT_CONFIG_DEFAULT}]
@registries.ZIGBEE_CHANNEL_REGISTRY.register(general.MultistateValue.cluster_id)
class MultistateValue(AttributeListeningChannel):
"""Multistate Value channel."""
@registries.ZIGBEE_CHANNEL_REGISTRY.register(general.AnalogValue.cluster_id)
class AnalogValue(AttributeListeningChannel):
"""Analog Value channel."""
REPORT_CONFIG = [{"attr": "present_value", "config": REPORT_CONFIG_DEFAULT}]
@registries.ZIGBEE_CHANNEL_REGISTRY.register(general.ApplianceControl.cluster_id)
class ApplianceContorl(ZigbeeChannel):
"""Appliance Control channel."""
pass
@registries.CHANNEL_ONLY_CLUSTERS.register(general.Basic.cluster_id)
@registries.ZIGBEE_CHANNEL_REGISTRY.register(general.Basic.cluster_id)
class BasicChannel(ZigbeeChannel):
"""Channel to interact with the basic cluster."""
UNKNOWN = 0
BATTERY = 3
POWER_SOURCES = {
UNKNOWN: "Unknown",
1: "Mains (single phase)",
2: "Mains (3 phase)",
BATTERY: "Battery",
4: "DC source",
5: "Emergency mains constantly powered",
6: "Emergency mains and transfer switch",
}
def populate_channel_registry():
"""Populate the channel registry."""
from zigpy import zcl
ZIGBEE_CHANNEL_REGISTRY.update(
{
zcl.clusters.closures.DoorLock.cluster_id: DoorLockChannel,
zcl.clusters.general.Alarms.cluster_id: ZigbeeChannel,
zcl.clusters.general.ApplianceControl.cluster_id: ZigbeeChannel,
zcl.clusters.general.Basic.cluster_id: BasicChannel,
zcl.clusters.general.Commissioning.cluster_id: ZigbeeChannel,
zcl.clusters.general.GreenPowerProxy.cluster_id: ZigbeeChannel,
zcl.clusters.general.Groups.cluster_id: ZigbeeChannel,
zcl.clusters.general.Identify.cluster_id: ZigbeeChannel,
zcl.clusters.general.LevelControl.cluster_id: LevelControlChannel,
zcl.clusters.general.OnOff.cluster_id: OnOffChannel,
zcl.clusters.general.OnOffConfiguration.cluster_id: ZigbeeChannel,
zcl.clusters.general.Ota.cluster_id: ZigbeeChannel,
zcl.clusters.general.Partition.cluster_id: ZigbeeChannel,
zcl.clusters.general.PollControl.cluster_id: ZigbeeChannel,
zcl.clusters.general.PowerConfiguration.cluster_id: PowerConfigurationChannel,
zcl.clusters.general.PowerProfile.cluster_id: ZigbeeChannel,
zcl.clusters.general.Scenes.cluster_id: ZigbeeChannel,
zcl.clusters.homeautomation.ElectricalMeasurement.cluster_id: ElectricalMeasurementChannel,
zcl.clusters.hvac.Fan.cluster_id: FanChannel,
zcl.clusters.lighting.Color.cluster_id: ColorChannel,
zcl.clusters.lightlink.LightLink.cluster_id: ZigbeeChannel,
zcl.clusters.security.IasZone.cluster_id: IASZoneChannel,
CONTROLLER: zigpy_xbee.zigbee.application.ControllerApplication,
ZHA_GW_RADIO_DESCRIPTION: "XBee",
}
RADIO_TYPES[RadioType.zigate.name] = {
ZHA_GW_RADIO: zigpy_zigate.api.ZiGate,
CONTROLLER: zigpy_zigate.zigbee.application.ControllerApplication,
ZHA_GW_RADIO_DESCRIPTION: "ZiGate",
}
BINARY_SENSOR_CLUSTERS.add(SMARTTHINGS_ACCELERATION_CLUSTER)
BINARY_SENSOR_TYPES.update(
{
SMARTTHINGS_ACCELERATION_CLUSTER: SENSOR_ACCELERATION,
zcl.clusters.general.OnOff.cluster_id: SENSOR_OPENING,
zcl.clusters.measurement.OccupancySensing.cluster_id: SENSOR_OCCUPANCY,
zcl.clusters.security.IasZone.cluster_id: ZONE,
}
)
DEVICE_CLASS[zigpy.profiles.zha.PROFILE_ID].update(
{
SMARTTHINGS_ARRIVAL_SENSOR_DEVICE_TYPE: DEVICE_TRACKER,
zigpy.profiles.zha.DeviceType.COLOR_DIMMABLE_LIGHT: LIGHT,
zigpy.profiles.zha.DeviceType.COLOR_TEMPERATURE_LIGHT: LIGHT,
zigpy.profiles.zha.DeviceType.DIMMABLE_BALLAST: LIGHT,
zigpy.profiles.zha.DeviceType.DIMMABLE_LIGHT: LIGHT,
zigpy.profiles.zha.DeviceType.DIMMABLE_PLUG_IN_UNIT: LIGHT,
zigpy.profiles.zha.DeviceType.EXTENDED_COLOR_LIGHT: LIGHT,
zigpy.profiles.zha.DeviceType.LEVEL_CONTROLLABLE_OUTPUT: LIGHT,
zigpy.profiles.zha.DeviceType.ON_OFF_BALLAST: SWITCH,