1 """Text entities for UniFi Protect."""
3 from __future__
import annotations
5 from collections.abc
import Sequence
6 from dataclasses
import dataclass
8 from uiprotect.data
import (
12 ProtectAdoptableDeviceModel,
20 from .data
import ProtectDeviceType, UFPConfigEntry
24 ProtectEntityDescription,
25 ProtectSetableKeysMixin,
27 async_all_device_entities,
31 @dataclass(frozen=True, kw_only=True)
33 """Describes UniFi Protect Text entity."""
37 if obj.lcd_message
is None:
38 return obj.api.bootstrap.nvr.doorbell_settings.default_message_text
39 return obj.lcd_message.text
43 await obj.set_lcd_text(DoorbellMessageType.CUSTOM_MESSAGE, text=message)
46 CAMERA: tuple[ProtectTextEntityDescription, ...] = (
50 entity_category=EntityCategory.CONFIG,
51 ufp_value_fn=_get_doorbell_current,
52 ufp_set_method_fn=_set_doorbell_message,
53 ufp_required_field=
"feature_flags.has_lcd_screen",
54 ufp_perm=PermRequired.WRITE,
58 _MODEL_DESCRIPTIONS: dict[ModelType, Sequence[ProtectEntityDescription]] = {
59 ModelType.CAMERA: CAMERA,
65 entry: UFPConfigEntry,
66 async_add_entities: AddEntitiesCallback,
68 """Set up sensors for UniFi Protect integration."""
69 data = entry.runtime_data
72 def _add_new_device(device: ProtectAdoptableDeviceModel) ->
None:
77 model_descriptions=_MODEL_DESCRIPTIONS,
82 data.async_subscribe_adopt(_add_new_device)
85 data, ProtectDeviceText, model_descriptions=_MODEL_DESCRIPTIONS
91 """A Ubiquiti UniFi Protect Sensor."""
93 entity_description: ProtectTextEntityDescription
94 _state_attrs = (
"_attr_available",
"_attr_native_value")
102 """Change the value."""
None async_set_value(self, str value)
None _async_update_device_from_protect(self, ProtectDeviceType device)
list[BaseProtectEntity] async_all_device_entities(ProtectData data, type[BaseProtectEntity] klass, dict[ModelType, Sequence[ProtectEntityDescription]]|None model_descriptions=None, Sequence[ProtectEntityDescription]|None all_descs=None, list[ProtectEntityDescription]|None unadopted_descs=None, ProtectAdoptableDeviceModel|None ufp_device=None)
str|None _get_doorbell_current(Camera obj)
None async_setup_entry(HomeAssistant hass, UFPConfigEntry entry, AddEntitiesCallback async_add_entities)
None _set_doorbell_message(Camera obj, str message)