| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- from homeassistant.core import HomeAssistant
- from homeassistant.const import EntityCategory
- from homeassistant.helpers.entity import Entity
- from homeassistant.components.text import TextEntity
- from homeassistant.helpers.entity_platform import AddEntitiesCallback
- from . import ZiBConfigEntry
- from .entity import ZiBEntityBase
- from .const import ROOM_STATE_TEXTS
- async def async_setup_entry(
- hass: HomeAssistant,
- config_entry: ZiBConfigEntry,
- async_add_entities: AddEntitiesCallback,
- ) -> None:
- state = config_entry.runtime_data.state
- async_add_entities([
- Reservation_Defaults(state),
- ])
- class ZiBTextBase(ZiBEntityBase, TextEntity):
- _attr_entity_category = EntityCategory.CONFIG
- def __init__(self, entity: Entity, name: str, icon: str = None):
- self._field = name.lower().replace(' ', '_')
- if self._field not in ROOM_STATE_TEXTS:
- raise KeyError(self._field)
- super().__init__(entity, name, f"{entity.id}_{self._field}", icon)
- # Fake in some values for testing
- for field in ROOM_STATE_TEXTS:
- self._entity.set(field, False)
- @property
- def state(self) -> str:
- return self._entity._data[self._field]
- async def async_set_value(self, value: str) -> None:
- field = self.name.lower().replace(' ', '_')
- entity = self.platform.config_entry.runtime_data.state
- entity.set(field, value)
- await entity.publish_updates()
- class Reservation_Defaults(ZiBTextBase):
- def __init__(self, state: RoomState):
- super().__init__(state, 'Reservation Defaults', 'mdi:format-list-group')
|