Пример #1
0
 async def async_set_brightness_belief(self, brightness: int) -> None:
     """Set the belief state of the light."""
     if not self._device.supports_set_brightness():
         raise HomeAssistantError(
             "This device does not support setting brightness")
     if brightness == 0:
         await self.async_set_power_belief(False)
         return
     try:
         await self._hub.bond.action(
             self._device.device_id,
             Action.set_brightness_belief(round((brightness * 100) / 255)),
         )
     except ClientResponseError as ex:
         raise HomeAssistantError(
             f"The bond API returned an error calling set_brightness_belief for {self.entity_id}.  Code: {ex.code}  Message: {ex.message}"
         ) from ex
Пример #2
0
async def test_fp_light_set_brightness_belief_full(hass: core.HomeAssistant):
    """Tests that the set brightness belief function of a light delegates to API."""
    await setup_platform(
        hass,
        LIGHT_DOMAIN,
        fireplace_with_light_supports_brightness("name-1"),
        bond_device_id="test-device-id",
    )

    with patch_bond_action() as mock_bond_action, patch_bond_device_state():
        await hass.services.async_call(
            DOMAIN,
            SERVICE_SET_LIGHT_BRIGHTNESS_TRACKED_STATE,
            {
                ATTR_ENTITY_ID: "light.name_1",
                ATTR_BRIGHTNESS: 255
            },
            blocking=True,
        )
        await hass.async_block_till_done()

    mock_bond_action.assert_called_once_with(
        "test-device-id", Action.set_brightness_belief(brightness=100))