1 """Support for NYT Games sensors."""
3 from collections.abc
import Callable
4 from dataclasses
import dataclass
5 from datetime
import date
7 from nyt_games
import Connections, SpellingBee, Wordle
12 SensorEntityDescription,
20 from .
import NYTGamesConfigEntry
21 from .coordinator
import NYTGamesCoordinator
22 from .entity
import ConnectionsEntity, SpellingBeeEntity, WordleEntity
25 @dataclass(frozen=True, kw_only=True)
27 """Describes a NYT Games Wordle sensor entity."""
29 value_fn: Callable[[Wordle], StateType]
32 WORDLE_SENSORS: tuple[NYTGamesWordleSensorEntityDescription, ...] = (
35 translation_key=
"wordles_played",
36 state_class=SensorStateClass.MEASUREMENT,
37 native_unit_of_measurement=
"games",
38 value_fn=
lambda wordle: wordle.games_played,
42 translation_key=
"won",
43 state_class=SensorStateClass.MEASUREMENT,
44 native_unit_of_measurement=
"games",
45 value_fn=
lambda wordle: wordle.games_won,
49 translation_key=
"streak",
50 state_class=SensorStateClass.TOTAL,
51 native_unit_of_measurement=UnitOfTime.DAYS,
52 device_class=SensorDeviceClass.DURATION,
53 value_fn=
lambda wordle: wordle.current_streak,
56 key=
"wordles_max_streak",
57 translation_key=
"max_streak",
58 state_class=SensorStateClass.TOTAL_INCREASING,
59 native_unit_of_measurement=UnitOfTime.DAYS,
60 device_class=SensorDeviceClass.DURATION,
61 value_fn=
lambda wordle: wordle.max_streak,
66 @dataclass(frozen=True, kw_only=True)
68 """Describes a NYT Games Spelling Bee sensor entity."""
70 value_fn: Callable[[SpellingBee], StateType]
73 SPELLING_BEE_SENSORS: tuple[NYTGamesSpellingBeeSensorEntityDescription, ...] = (
75 key=
"spelling_bees_played",
76 translation_key=
"spelling_bees_played",
77 state_class=SensorStateClass.TOTAL,
78 native_unit_of_measurement=
"games",
79 value_fn=
lambda spelling_bee: spelling_bee.puzzles_started,
82 key=
"spelling_bees_total_words",
83 translation_key=
"total_words",
84 state_class=SensorStateClass.TOTAL,
85 native_unit_of_measurement=
"words",
86 entity_registry_enabled_default=
False,
87 value_fn=
lambda spelling_bee: spelling_bee.total_words,
90 key=
"spelling_bees_total_pangrams",
91 translation_key=
"total_pangrams",
92 state_class=SensorStateClass.TOTAL,
93 native_unit_of_measurement=
"pangrams",
94 entity_registry_enabled_default=
False,
95 value_fn=
lambda spelling_bee: spelling_bee.total_pangrams,
100 @dataclass(frozen=True, kw_only=True)
102 """Describes a NYT Games Connections sensor entity."""
104 value_fn: Callable[[Connections], StateType | date]
107 CONNECTIONS_SENSORS: tuple[NYTGamesConnectionsSensorEntityDescription, ...] = (
109 key=
"connections_played",
110 translation_key=
"connections_played",
111 state_class=SensorStateClass.TOTAL,
112 native_unit_of_measurement=
"games",
113 value_fn=
lambda connections: connections.puzzles_completed,
116 key=
"connections_won",
117 translation_key=
"won",
118 state_class=SensorStateClass.TOTAL,
119 native_unit_of_measurement=
"games",
120 value_fn=
lambda connections: connections.puzzles_won,
123 key=
"connections_last_played",
124 translation_key=
"last_played",
125 device_class=SensorDeviceClass.DATE,
126 value_fn=
lambda connections: connections.last_completed,
129 key=
"connections_streak",
130 translation_key=
"streak",
131 state_class=SensorStateClass.TOTAL,
132 native_unit_of_measurement=UnitOfTime.DAYS,
133 device_class=SensorDeviceClass.DURATION,
134 value_fn=
lambda connections: connections.current_streak,
137 key=
"connections_max_streak",
138 translation_key=
"max_streak",
139 state_class=SensorStateClass.TOTAL_INCREASING,
140 native_unit_of_measurement=UnitOfTime.DAYS,
141 device_class=SensorDeviceClass.DURATION,
142 value_fn=
lambda connections: connections.max_streak,
149 entry: NYTGamesConfigEntry,
150 async_add_entities: AddEntitiesCallback,
152 """Set up NYT Games sensor entities based on a config entry."""
154 coordinator = entry.runtime_data
156 entities: list[SensorEntity] = [
159 if coordinator.data.spelling_bee
is not None:
162 for description
in SPELLING_BEE_SENSORS
164 if coordinator.data.connections
is not None:
167 for description
in CONNECTIONS_SENSORS
174 """Defines a NYT Games sensor."""
176 entity_description: NYTGamesWordleSensorEntityDescription
180 coordinator: NYTGamesCoordinator,
181 description: NYTGamesWordleSensorEntityDescription,
183 """Initialize NYT Games sensor."""
187 f
"{coordinator.config_entry.unique_id}-wordle-{description.key}"
192 """Return the state of the sensor."""
197 """Defines a NYT Games sensor."""
199 entity_description: NYTGamesSpellingBeeSensorEntityDescription
203 coordinator: NYTGamesCoordinator,
204 description: NYTGamesSpellingBeeSensorEntityDescription,
206 """Initialize NYT Games sensor."""
210 f
"{coordinator.config_entry.unique_id}-spelling_bee-{description.key}"
215 """Return the state of the sensor."""
216 assert self.coordinator.data.spelling_bee
is not None
221 """Defines a NYT Games sensor."""
223 entity_description: NYTGamesConnectionsSensorEntityDescription
227 coordinator: NYTGamesCoordinator,
228 description: NYTGamesConnectionsSensorEntityDescription,
230 """Initialize NYT Games sensor."""
234 f
"{coordinator.config_entry.unique_id}-connections-{description.key}"
239 """Return the state of the sensor."""
240 assert self.coordinator.data.connections
is not None
StateType|date native_value(self)
None __init__(self, NYTGamesCoordinator coordinator, NYTGamesConnectionsSensorEntityDescription description)
None __init__(self, NYTGamesCoordinator coordinator, NYTGamesSpellingBeeSensorEntityDescription description)
StateType native_value(self)
StateType native_value(self)
None __init__(self, NYTGamesCoordinator coordinator, NYTGamesWordleSensorEntityDescription description)
None async_setup_entry(HomeAssistant hass, NYTGamesConfigEntry entry, AddEntitiesCallback async_add_entities)