How to use the zigpy.zcl.clusters.general.Basic function in zigpy

To help you get started, we’ve selected a few zigpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zigpy / zigpy / tests / test_zcl_clusters.py View on Github external
def test_basic_cluster_power_source():
    extra = b"The rest of the owl\xaa\x55"
    pwr_src, rest = zcl.clusters.general.Basic.PowerSource.deserialize(b"\x81" + extra)

    assert rest == extra
    assert pwr_src == zcl.clusters.general.Basic.PowerSource.Mains_single_phase
    assert pwr_src == 0x01
    assert pwr_src.value == 0x01
    assert pwr_src.battery_backup
github home-assistant / home-assistant / tests / components / zha / test_device_trigger.py View on Github external
async def test_triggers(hass, config_entry, zha_gateway):
    """Test zha device triggers."""
    from zigpy.zcl.clusters.general import OnOff, Basic

    # create zigpy device
    zigpy_device = await async_init_zigpy_device(
        hass, [Basic.cluster_id], [OnOff.cluster_id], None, zha_gateway
    )

    zigpy_device.device_automation_triggers = {
        (SHAKEN, SHAKEN): {COMMAND: COMMAND_SHAKE},
        (DOUBLE_PRESS, DOUBLE_PRESS): {COMMAND: COMMAND_DOUBLE},
        (SHORT_PRESS, SHORT_PRESS): {COMMAND: COMMAND_SINGLE},
        (LONG_PRESS, LONG_PRESS): {COMMAND: COMMAND_HOLD},
        (LONG_RELEASE, LONG_RELEASE): {COMMAND: COMMAND_HOLD},
    }

    await hass.config_entries.async_forward_entry_setup(config_entry, DOMAIN)
    await hass.async_block_till_done()
    hass.config_entries._entries.append(config_entry)

    zha_device = zha_gateway.get_device(zigpy_device.ieee)
    ieee_address = str(zha_device.ieee)
github home-assistant / home-assistant / tests / components / zha / test_device_action.py View on Github external
async def test_get_actions(hass, config_entry, zha_gateway):
    """Test we get the expected actions from a zha device."""
    from zigpy.zcl.clusters.general import Basic
    from zigpy.zcl.clusters.security import IasZone, IasWd

    # create zigpy device
    zigpy_device = await async_init_zigpy_device(
        hass,
        [Basic.cluster_id, IasZone.cluster_id, IasWd.cluster_id],
        [],
        None,
        zha_gateway,
    )

    await hass.config_entries.async_forward_entry_setup(config_entry, "binary_sensor")
    await hass.async_block_till_done()
    hass.config_entries._entries.append(config_entry)

    zha_device = zha_gateway.get_device(zigpy_device.ieee)
    ieee_address = str(zha_device.ieee)

    ha_device_registry = await async_get_registry(hass)
    reg_device = ha_device_registry.async_get_device({(DOMAIN, ieee_address)}, set())

    actions = await async_get_device_automations(hass, "action", reg_device.id)
github home-assistant / home-assistant / tests / components / zha / test_device_trigger.py View on Github external
async def test_exception_bad_trigger(hass, config_entry, zha_gateway, calls, caplog):
    """Test for exception on event triggers firing."""
    from zigpy.zcl.clusters.general import OnOff, Basic

    # create zigpy device
    zigpy_device = await async_init_zigpy_device(
        hass, [Basic.cluster_id], [OnOff.cluster_id], None, zha_gateway
    )

    zigpy_device.device_automation_triggers = {
        (SHAKEN, SHAKEN): {COMMAND: COMMAND_SHAKE},
        (DOUBLE_PRESS, DOUBLE_PRESS): {COMMAND: COMMAND_DOUBLE},
        (SHORT_PRESS, SHORT_PRESS): {COMMAND: COMMAND_SINGLE},
        (LONG_PRESS, LONG_PRESS): {COMMAND: COMMAND_HOLD},
        (LONG_RELEASE, LONG_RELEASE): {COMMAND: COMMAND_HOLD},
    }

    await hass.config_entries.async_forward_entry_setup(config_entry, DOMAIN)
    await hass.async_block_till_done()
    hass.config_entries._entries.append(config_entry)

    zha_device = zha_gateway.get_device(zigpy_device.ieee)
github home-assistant / home-assistant / tests / components / zha / test_sensor.py View on Github external
This will build devices for all cluster ids that exist in cluster_ids.
    They get added to the network and then the sensor component is loaded
    which will cause sensor entites to get created for each device.
    A dict containing relevant device info for testing is returned. It contains
    the entity id, zigpy device, and the zigbee cluster for the sensor.
    """

    device_infos = {}
    counter = 0
    for cluster_id in cluster_ids:
        # create zigpy device
        device_infos[cluster_id] = {"zigpy_device": None}
        device_infos[cluster_id]["zigpy_device"] = await async_init_zigpy_device(
            hass,
            [cluster_id, general.Basic.cluster_id],
            [],
            None,
            zha_gateway,
            ieee="00:15:8d:00:02:32:4f:0{}".format(counter),
            manufacturer="Fake{}".format(cluster_id),
            model="FakeModel{}".format(cluster_id),
        )

        counter += 1

    # load up sensor domain
    await hass.config_entries.async_forward_entry_setup(config_entry, DOMAIN)
    await hass.async_block_till_done()

    # put the other relevant info in the device info dict
    for cluster_id in cluster_ids:
github zigpy / zigpy / tests / test_zcl_clusters.py View on Github external
def test_basic_cluster_power_source():
    extra = b"The rest of the owl\xaa\x55"
    pwr_src, rest = zcl.clusters.general.Basic.PowerSource.deserialize(b"\x81" + extra)

    assert rest == extra
    assert pwr_src == zcl.clusters.general.Basic.PowerSource.Mains_single_phase
    assert pwr_src == 0x01
    assert pwr_src.value == 0x01
    assert pwr_src.battery_backup
github home-assistant / home-assistant / tests / components / zha / test_lock.py View on Github external
async def test_lock(hass, config_entry, zha_gateway):
    """Test zha lock platform."""
    from zigpy.zcl.clusters.closures import DoorLock
    from zigpy.zcl.clusters.general import Basic

    # create zigpy device
    zigpy_device = await async_init_zigpy_device(
        hass, [DoorLock.cluster_id, Basic.cluster_id], [], None, zha_gateway
    )

    # load up lock domain
    await hass.config_entries.async_forward_entry_setup(config_entry, DOMAIN)
    await hass.async_block_till_done()

    cluster = zigpy_device.endpoints.get(1).door_lock
    entity_id = make_entity_id(DOMAIN, zigpy_device, cluster)
    zha_device = zha_gateway.get_device(zigpy_device.ieee)

    # test that the lock was created and that it is unavailable
    assert hass.states.get(entity_id).state == STATE_UNAVAILABLE

    # allow traffic to flow through the gateway and device
    await async_enable_traffic(hass, zha_gateway, [zha_device])
github zigpy / zigpy / zigpy / endpoint.py View on Github external
async def get_model_info(self):
        if Basic.cluster_id not in self.in_clusters:
            return None, None

        attributes = {"manufacturer": None, "model": None}

        async def read(attribute_names):
            """Read attributes and update extra_info convenience function."""
            try:
                result, _ = await self.basic.read_attributes(
                    attribute_names, allow_cache=True
                )
                attributes.update(result)
            except (zigpy.exceptions.ZigbeeException, asyncio.TimeoutError):
                pass

        await read(["manufacturer", "model"])
github home-assistant / home-assistant / homeassistant / components / zha / core / listeners.py View on Github external
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,
        zcl.clusters.general.PowerConfiguration.cluster_id: BatteryListener,
        zcl.clusters.general.Basic.cluster_id: BasicListener,
        zcl.clusters.security.IasZone.cluster_id: IASZoneListener,
        zcl.clusters.hvac.Fan.cluster_id: FanListener,
    })
github home-assistant / home-assistant / homeassistant / components / zha / core / channels / general.py View on Github external
@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",
    }