Handle bytes data in sql sensors (#89169)

This commit is contained in:
J. Nick Koston
2023-03-13 18:07:05 -10:00
committed by GitHub
parent afa58b80bd
commit 2cb673db04
3 changed files with 29 additions and 2 deletions

View File

@@ -242,10 +242,15 @@ class SQLSensor(SensorEntity):
for key, value in res.items():
if isinstance(value, decimal.Decimal):
value = float(value)
if isinstance(value, date):
elif isinstance(value, date):
value = value.isoformat()
elif isinstance(value, (bytes, bytearray)):
value = f"0x{value.hex()}"
self._attr_extra_state_attributes[key] = value
if data is not None and isinstance(data, (bytes, bytearray)):
data = f"0x{data.hex()}"
if data is not None and self._template is not None:
self._attr_native_value = (
self._template.async_render_with_possible_json_value(data, None)