1 """Mastodon platform for sensor components."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
11 SensorEntityDescription,
18 from .
import MastodonConfigEntry
20 ACCOUNT_FOLLOWERS_COUNT,
21 ACCOUNT_FOLLOWING_COUNT,
22 ACCOUNT_STATUSES_COUNT,
24 from .entity
import MastodonEntity
27 @dataclass(frozen=True, kw_only=True)
29 """Describes Mastodon sensor entity."""
31 value_fn: Callable[[dict[str, Any]], StateType]
34 ENTITY_DESCRIPTIONS = (
37 translation_key=
"followers",
38 state_class=SensorStateClass.TOTAL,
39 value_fn=
lambda data: data.get(ACCOUNT_FOLLOWERS_COUNT),
43 translation_key=
"following",
44 state_class=SensorStateClass.TOTAL,
45 value_fn=
lambda data: data.get(ACCOUNT_FOLLOWING_COUNT),
49 translation_key=
"posts",
50 state_class=SensorStateClass.TOTAL,
51 value_fn=
lambda data: data.get(ACCOUNT_STATUSES_COUNT),
58 entry: MastodonConfigEntry,
59 async_add_entities: AddEntitiesCallback,
61 """Set up the sensor platform for entity."""
62 coordinator = entry.runtime_data.coordinator
66 coordinator=coordinator,
67 entity_description=entity_description,
70 for entity_description
in ENTITY_DESCRIPTIONS
75 """A Mastodon sensor entity."""
77 entity_description: MastodonSensorEntityDescription
81 """Return the native value of the sensor."""
StateType native_value(self)
None async_setup_entry(HomeAssistant hass, MastodonConfigEntry entry, AddEntitiesCallback async_add_entities)