44
55import logging
66from collections .abc import Iterable
7+ from datetime import datetime
78from fnmatch import fnmatch
89from os import walk
910from os .path import dirname , join , splitext
1011from typing import Any
1112
1213from homeassistant .components .binary_sensor import BinarySensorEntityDescription
1314from homeassistant .components .number import NumberEntityDescription , NumberMode
14- from homeassistant .components .sensor import SensorEntityDescription
15+ from homeassistant .components .select import SelectEntityDescription
16+ from homeassistant .components .sensor import SensorDeviceClass , SensorEntityDescription
1517from homeassistant .components .switch import SwitchEntityDescription
1618from homeassistant .const import EntityCategory , Platform , UnitOfTemperature
1719from homeassistant .helpers .entity import EntityDescription
@@ -221,11 +223,31 @@ def max(self):
221223 """Return maximum valid value."""
222224 return self ._range ["max" ]
223225
226+ @property
227+ def entity_registry_enabled_default (self ):
228+ """Return true if entity should be enabled by default."""
229+ return self ._config .get ("enabled_default" , True )
230+
231+ @property
232+ def entity_registry_visible_default (self ):
233+ """Return true if entity should be visible by default."""
234+ return self .entity_registry_enabled_default and self ._config .get ("visible_default" , True )
235+
236+ @property
237+ def options (self ):
238+ """Return options for select entity."""
239+ return [mapping ["value" ] for mapping in self ._mappings ]
240+
224241 @property
225242 def _mappings (self ):
226243 return self ._config .get ("mapping" , [])
227244
228245 def _get_value_for_native (self , native_value : Any ):
246+ if self .device_class == SensorDeviceClass .TIMESTAMP :
247+ now = datetime .now ()
248+ local_now = now .astimezone ()
249+ local_tz = local_now .tzinfo
250+ return datetime .fromtimestamp (native_value , tz = local_tz )
229251 for mapping in self ._mappings :
230252 if mapping .get ("native_value" ) == native_value :
231253 value = mapping .get ("value" )
@@ -343,6 +365,8 @@ def entity_description(self) -> EntityDescription:
343365 translation_key = self .translation_key ,
344366 translation_placeholders = self .translation_placeholders ,
345367 name = None if self .is_primary else self .name ,
368+ entity_registry_enabled_default = self .entity_registry_enabled_default ,
369+ entity_registry_visible_default = self .entity_registry_visible_default ,
346370 has_entity_name = True ,
347371 )
348372
@@ -367,6 +391,14 @@ def switch_entity_description(self) -> SwitchEntityDescription:
367391 """Return switch entity description."""
368392 return SwitchEntityDescription (** self .entity_description .__dict__ )
369393
394+ @property
395+ def select_entity_description (self ) -> SelectEntityDescription :
396+ """Return select entity description."""
397+ return SelectEntityDescription (
398+ key = self .key ,
399+ options = [mapping ["value" ] for mapping in self ._mappings ],
400+ )
401+
370402 @property
371403 def number_entity_description (self ) -> NumberEntityDescription :
372404 """Return number entity description."""
0 commit comments