1 """Support for govee_ble event entities."""
3 from __future__
import annotations
5 from govee_ble
import ModelInfo, SensorType
8 BluetoothServiceInfoBleak,
9 async_last_service_info,
14 EventEntityDescription,
21 from .const
import DOMAIN
22 from .coordinator
import GoveeBLEConfigEntry, format_event_dispatcher_name
24 BUTTON_DESCRIPTIONS = [
27 translation_key=f
"button_{i}",
28 event_types=[
"press"],
29 device_class=EventDeviceClass.BUTTON,
35 event_types=[
"motion"],
36 device_class=EventDeviceClass.MOTION,
40 event_types=[
"vibration"],
41 translation_key=
"vibration",
46 """Representation of a govee ble event entity."""
48 _attr_should_poll =
False
49 _attr_has_entity_name =
True
53 model_info: ModelInfo,
54 service_info: BluetoothServiceInfoBleak |
None,
56 description: EventEntityDescription,
58 """Initialise a govee ble event entity."""
61 name = service_info.name
if service_info
else model_info.model_id
64 identifiers={(DOMAIN, address)},
65 connections={(dr.CONNECTION_BLUETOOTH, address)},
74 """Entity added to hass."""
92 entry: GoveeBLEConfigEntry,
93 async_add_entities: AddEntitiesCallback,
95 """Set up a govee ble event."""
96 coordinator = entry.runtime_data
97 if not (model_info := coordinator.model_info):
99 address = coordinator.address
100 sensor_type = model_info.sensor_type
101 if sensor_type
is SensorType.MOTION:
102 descriptions = [MOTION_DESCRIPTION]
103 elif sensor_type
is SensorType.VIBRATION:
104 descriptions = [VIBRATION_DESCRIPTION]
105 elif sensor_type
is SensorType.BUTTON:
106 button_count = model_info.button_count
107 descriptions = BUTTON_DESCRIPTIONS[0:button_count]
113 for description
in descriptions
list[str] event_types(self)
None _trigger_event(self, str event_type, dict[str, Any]|None event_attributes=None)
None async_added_to_hass(self)
None __init__(self, ModelInfo model_info, BluetoothServiceInfoBleak|None service_info, str address, EventEntityDescription description)
None _async_handle_event(self)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
BluetoothServiceInfoBleak|None async_last_service_info(HomeAssistant hass, str address, bool connectable=True)
SignalType[BTHomeBleEvent] format_event_dispatcher_name(str address, str event_class)
None async_setup_entry(HomeAssistant hass, GoveeBLEConfigEntry entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)