1 """Support for Bond generic devices."""
3 from __future__
import annotations
7 from aiohttp.client_exceptions
import ClientResponseError
8 from bond_async
import Action, DeviceType
9 import voluptuous
as vol
17 from .
import BondConfigEntry
18 from .const
import ATTR_POWER_STATE, SERVICE_SET_POWER_TRACKED_STATE
19 from .entity
import BondEntity
24 entry: BondConfigEntry,
25 async_add_entities: AddEntitiesCallback,
27 """Set up Bond generic devices."""
28 data = entry.runtime_data
29 platform = entity_platform.async_get_current_platform()
30 platform.async_register_entity_service(
31 SERVICE_SET_POWER_TRACKED_STATE,
32 {vol.Required(ATTR_POWER_STATE): cv.boolean},
33 "async_set_power_belief",
38 for device
in data.hub.devices
39 if DeviceType.is_generic(device.type)
44 """Representation of a Bond generic device."""
50 """Turn the device on."""
51 await self.
_bond_bond.action(self.
_device_id_device_id, Action.turn_on())
54 """Turn the device off."""
55 await self.
_bond_bond.action(self.
_device_id_device_id, Action.turn_off())
58 """Set switch power belief."""
60 await self.
_bond_bond.action(
61 self.
_device_id_device_id, Action.set_power_state_belief(power_state)
63 except ClientResponseError
as ex:
65 "The bond API returned an error calling set_power_state_belief for"
66 f
" {self.entity_id}. Code: {ex.status} Message: {ex.message}"
None async_set_power_belief(self, bool power_state)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, BondConfigEntry entry, AddEntitiesCallback async_add_entities)