Skip to content

Commit

Permalink
Отключено сохранение истории аттрибутов
Browse files Browse the repository at this point in the history
  • Loading branch information
egmen committed Nov 11, 2024
1 parent 24fcd87 commit fdd325d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ sensor:
stop_id: 2b348a58-a3e4-4937-b973-18cfe0f87e5e
```
## Чтобы не сохранять историю изменения сенсора в базе данных
## Сохранение истории сенсора
- История аттрибутов не сохраняется в базе данных
- Чтобы не сохранять историю полностью, нужно в `configuration.yaml` добавить:
```yaml
# Пример configuration.yaml
recorder:
exclude:
entity_globs:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/moscow_transport/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/egmen/moscow_transport/issues",
"requirements": [],
"version": "24.11.1"
"version": "24.11.2"
}
7 changes: 6 additions & 1 deletion custom_components/moscow_transport/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
SensorDeviceClass,
SensorEntity,
)
from homeassistant.const import CONF_NAME
from homeassistant.const import CONF_NAME, MATCH_ALL
from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_create_clientsession
import homeassistant.helpers.config_validation as cv
Expand Down Expand Up @@ -74,6 +74,9 @@ class DiscoverMoscowTransport(SensorEntity):
_attr_device_class = SensorDeviceClass.TIMESTAMP
_attr_friendly_name = "hello world"

# Не сохранять историю аттрибутов
_unrecorded_attributes = frozenset({MATCH_ALL})

def __init__(self, session, stop_id, routes, name) -> None:
"""Initialize sensor."""
self.session = session
Expand Down Expand Up @@ -107,9 +110,11 @@ async def async_update(self, *, tries=0):
if closest_route:
telemetry_suffix = get_telemetry_suffix(closest_route[2])
self._name = f"{self._name} ({closest_route[0]}{telemetry_suffix})"
# do not save _state change in history
self._state = dt_util.utcnow(
) + timedelta(seconds=closest_route[1])


for route in stop_info['routePath']:

if self._routes and route['number'] not in self._routes:
Expand Down

0 comments on commit fdd325d

Please sign in to comment.