Fix ESPHome timestamp sensor (#50305)
This commit is contained in:
parent
4853fb7966
commit
61b0e66405
1 changed files with 8 additions and 1 deletions
|
@ -6,10 +6,15 @@ import math
|
|||
from aioesphomeapi import SensorInfo, SensorState, TextSensorInfo, TextSensorState
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import DEVICE_CLASSES, SensorEntity
|
||||
from homeassistant.components.sensor import (
|
||||
DEVICE_CLASS_TIMESTAMP,
|
||||
DEVICE_CLASSES,
|
||||
SensorEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.util import dt
|
||||
|
||||
from . import EsphomeEntity, esphome_state_property, platform_async_setup_entry
|
||||
|
||||
|
@ -74,6 +79,8 @@ class EsphomeSensor(EsphomeEntity, SensorEntity):
|
|||
return None
|
||||
if self._state.missing_state:
|
||||
return None
|
||||
if self.device_class == DEVICE_CLASS_TIMESTAMP:
|
||||
return dt.utc_from_timestamp(self._state.state).isoformat()
|
||||
return f"{self._state.state:.{self._static_info.accuracy_decimals}f}"
|
||||
|
||||
@property
|
||||
|
|
Loading…
Add table
Reference in a new issue