Skip to content

Commit d4be238

Browse files
frenckmarcelveldt
authored andcommitted
Collection of DeviceClass related typing fixes (#82931)
1 parent fff099e commit d4be238

File tree

13 files changed

+49
-41
lines changed

13 files changed

+49
-41
lines changed

homeassistant/components/command_line/binary_sensor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from homeassistant.components.binary_sensor import (
99
DEVICE_CLASSES_SCHEMA,
1010
PLATFORM_SCHEMA,
11+
BinarySensorDeviceClass,
1112
BinarySensorEntity,
1213
)
1314
from homeassistant.const import (
@@ -64,7 +65,7 @@ def setup_platform(
6465
command: str = config[CONF_COMMAND]
6566
payload_off: str = config[CONF_PAYLOAD_OFF]
6667
payload_on: str = config[CONF_PAYLOAD_ON]
67-
device_class: str | None = config.get(CONF_DEVICE_CLASS)
68+
device_class: BinarySensorDeviceClass | None = config.get(CONF_DEVICE_CLASS)
6869
value_template: Template | None = config.get(CONF_VALUE_TEMPLATE)
6970
command_timeout: int = config[CONF_COMMAND_TIMEOUT]
7071
unique_id: str | None = config.get(CONF_UNIQUE_ID)
@@ -95,7 +96,7 @@ def __init__(
9596
self,
9697
data: CommandSensorData,
9798
name: str,
98-
device_class: str | None,
99+
device_class: BinarySensorDeviceClass | None,
99100
payload_on: str,
100101
payload_off: str,
101102
value_template: Template | None,

homeassistant/components/fibaro/binary_sensor.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from collections.abc import Mapping
55
import json
6-
from typing import Any
6+
from typing import Any, cast
77

88
from homeassistant.components.binary_sensor import (
99
ENTITY_ID_FORMAT,
@@ -69,7 +69,9 @@ def __init__(self, fibaro_device: Any) -> None:
6969
elif fibaro_device.baseType in SENSOR_TYPES:
7070
self._fibaro_sensor_type = fibaro_device.baseType
7171
if self._fibaro_sensor_type:
72-
self._attr_device_class = SENSOR_TYPES[self._fibaro_sensor_type][2]
72+
self._attr_device_class = cast(
73+
BinarySensorDeviceClass, SENSOR_TYPES[self._fibaro_sensor_type][2]
74+
)
7375
self._attr_icon = SENSOR_TYPES[self._fibaro_sensor_type][1]
7476

7577
@property

homeassistant/components/geniushub/sensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def icon(self) -> str:
8181
return icon
8282

8383
@property
84-
def device_class(self) -> str:
84+
def device_class(self) -> SensorDeviceClass:
8585
"""Return the device class of the sensor."""
8686
return SensorDeviceClass.BATTERY
8787

homeassistant/components/group/binary_sensor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
DEVICE_CLASSES_SCHEMA,
88
DOMAIN as BINARY_SENSOR_DOMAIN,
99
PLATFORM_SCHEMA,
10+
BinarySensorDeviceClass,
1011
BinarySensorEntity,
1112
)
1213
from homeassistant.config_entries import ConfigEntry
@@ -94,7 +95,7 @@ def __init__(
9495
self,
9596
unique_id: str | None,
9697
name: str,
97-
device_class: str | None,
98+
device_class: BinarySensorDeviceClass | None,
9899
entity_ids: list[str],
99100
mode: str | None,
100101
) -> None:
@@ -149,6 +150,6 @@ def async_update_group_state(self) -> None:
149150
self._attr_is_on = self.mode(state == STATE_ON for state in states)
150151

151152
@property
152-
def device_class(self) -> str | None:
153+
def device_class(self) -> BinarySensorDeviceClass | None:
153154
"""Return the sensor class of the binary sensor."""
154155
return self._device_class

homeassistant/components/homematicip_cloud/binary_sensor.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class HomematicipBaseActionSensor(HomematicipGenericEntity, BinarySensorEntity):
195195
"""Representation of the HomematicIP base action sensor."""
196196

197197
@property
198-
def device_class(self) -> str:
198+
def device_class(self) -> BinarySensorDeviceClass:
199199
"""Return the class of this sensor."""
200200
return BinarySensorDeviceClass.MOVING
201201

@@ -240,7 +240,7 @@ def __init__(
240240
)
241241

242242
@property
243-
def device_class(self) -> str:
243+
def device_class(self) -> BinarySensorDeviceClass:
244244
"""Return the class of this sensor."""
245245
return BinarySensorDeviceClass.OPENING
246246

@@ -274,7 +274,7 @@ def __init__(
274274
self.has_additional_state = has_additional_state
275275

276276
@property
277-
def device_class(self) -> str:
277+
def device_class(self) -> BinarySensorDeviceClass:
278278
"""Return the class of this sensor."""
279279
return BinarySensorDeviceClass.DOOR
280280

@@ -295,7 +295,7 @@ class HomematicipMotionDetector(HomematicipGenericEntity, BinarySensorEntity):
295295
"""Representation of the HomematicIP motion detector."""
296296

297297
@property
298-
def device_class(self) -> str:
298+
def device_class(self) -> BinarySensorDeviceClass:
299299
"""Return the class of this sensor."""
300300
return BinarySensorDeviceClass.MOTION
301301

@@ -309,7 +309,7 @@ class HomematicipPresenceDetector(HomematicipGenericEntity, BinarySensorEntity):
309309
"""Representation of the HomematicIP presence detector."""
310310

311311
@property
312-
def device_class(self) -> str:
312+
def device_class(self) -> BinarySensorDeviceClass:
313313
"""Return the class of this sensor."""
314314
return BinarySensorDeviceClass.PRESENCE
315315

@@ -323,7 +323,7 @@ class HomematicipSmokeDetector(HomematicipGenericEntity, BinarySensorEntity):
323323
"""Representation of the HomematicIP smoke detector."""
324324

325325
@property
326-
def device_class(self) -> str:
326+
def device_class(self) -> BinarySensorDeviceClass:
327327
"""Return the class of this sensor."""
328328
return BinarySensorDeviceClass.SMOKE
329329

@@ -342,7 +342,7 @@ class HomematicipWaterDetector(HomematicipGenericEntity, BinarySensorEntity):
342342
"""Representation of the HomematicIP water detector."""
343343

344344
@property
345-
def device_class(self) -> str:
345+
def device_class(self) -> BinarySensorDeviceClass:
346346
"""Return the class of this sensor."""
347347
return BinarySensorDeviceClass.MOISTURE
348348

@@ -378,7 +378,7 @@ def __init__(self, hap: HomematicipHAP, device) -> None:
378378
super().__init__(hap, device, "Raining")
379379

380380
@property
381-
def device_class(self) -> str:
381+
def device_class(self) -> BinarySensorDeviceClass:
382382
"""Return the class of this sensor."""
383383
return BinarySensorDeviceClass.MOISTURE
384384

@@ -396,7 +396,7 @@ def __init__(self, hap: HomematicipHAP, device) -> None:
396396
super().__init__(hap, device, post="Sunshine")
397397

398398
@property
399-
def device_class(self) -> str:
399+
def device_class(self) -> BinarySensorDeviceClass:
400400
"""Return the class of this sensor."""
401401
return BinarySensorDeviceClass.LIGHT
402402

@@ -425,7 +425,7 @@ def __init__(self, hap: HomematicipHAP, device) -> None:
425425
super().__init__(hap, device, post="Battery")
426426

427427
@property
428-
def device_class(self) -> str:
428+
def device_class(self) -> BinarySensorDeviceClass:
429429
"""Return the class of this sensor."""
430430
return BinarySensorDeviceClass.BATTERY
431431

@@ -445,7 +445,7 @@ def __init__(self, hap: HomematicipHAP, device) -> None:
445445
super().__init__(hap, device)
446446

447447
@property
448-
def device_class(self) -> str:
448+
def device_class(self) -> BinarySensorDeviceClass:
449449
"""Return the class of this sensor."""
450450
return BinarySensorDeviceClass.POWER
451451

@@ -464,7 +464,7 @@ def __init__(self, hap: HomematicipHAP, device, post: str = "SecurityZone") -> N
464464
super().__init__(hap, device, post=post)
465465

466466
@property
467-
def device_class(self) -> str:
467+
def device_class(self) -> BinarySensorDeviceClass:
468468
"""Return the class of this sensor."""
469469
return BinarySensorDeviceClass.SAFETY
470470

homeassistant/components/homematicip_cloud/sensor.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def __init__(self, hap: HomematicipHAP, device) -> None:
205205
super().__init__(hap, device, post="Humidity")
206206

207207
@property
208-
def device_class(self) -> str:
208+
def device_class(self) -> SensorDeviceClass:
209209
"""Return the device class of the sensor."""
210210
return SensorDeviceClass.HUMIDITY
211211

@@ -230,7 +230,7 @@ def __init__(self, hap: HomematicipHAP, device) -> None:
230230
super().__init__(hap, device, post="Temperature")
231231

232232
@property
233-
def device_class(self) -> str:
233+
def device_class(self) -> SensorDeviceClass:
234234
"""Return the device class of the sensor."""
235235
return SensorDeviceClass.TEMPERATURE
236236

@@ -269,7 +269,7 @@ def __init__(self, hap: HomematicipHAP, device) -> None:
269269
super().__init__(hap, device, post="Illuminance")
270270

271271
@property
272-
def device_class(self) -> str:
272+
def device_class(self) -> SensorDeviceClass:
273273
"""Return the device class of the sensor."""
274274
return SensorDeviceClass.ILLUMINANCE
275275

@@ -308,7 +308,7 @@ def __init__(self, hap: HomematicipHAP, device) -> None:
308308
super().__init__(hap, device, post="Power")
309309

310310
@property
311-
def device_class(self) -> str:
311+
def device_class(self) -> SensorDeviceClass:
312312
"""Return the device class of the sensor."""
313313
return SensorDeviceClass.POWER
314314

@@ -333,7 +333,7 @@ def __init__(self, hap: HomematicipHAP, device) -> None:
333333
super().__init__(hap, device, post="Energy")
334334

335335
@property
336-
def device_class(self) -> str:
336+
def device_class(self) -> SensorDeviceClass:
337337
"""Return the device class of the sensor."""
338338
return SensorDeviceClass.ENERGY
339339

@@ -411,7 +411,7 @@ def __init__(self, hap: HomematicipHAP, device) -> None:
411411
super().__init__(hap, device, post="Channel 1 Temperature")
412412

413413
@property
414-
def device_class(self) -> str:
414+
def device_class(self) -> SensorDeviceClass:
415415
"""Return the device class of the sensor."""
416416
return SensorDeviceClass.TEMPERATURE
417417

@@ -436,7 +436,7 @@ def __init__(self, hap: HomematicipHAP, device) -> None:
436436
super().__init__(hap, device, post="Channel 2 Temperature")
437437

438438
@property
439-
def device_class(self) -> str:
439+
def device_class(self) -> SensorDeviceClass:
440440
"""Return the device class of the sensor."""
441441
return SensorDeviceClass.TEMPERATURE
442442

@@ -461,7 +461,7 @@ def __init__(self, hap: HomematicipHAP, device) -> None:
461461
super().__init__(hap, device, post="Delta Temperature")
462462

463463
@property
464-
def device_class(self) -> str:
464+
def device_class(self) -> SensorDeviceClass:
465465
"""Return the device class of the sensor."""
466466
return SensorDeviceClass.TEMPERATURE
467467

homeassistant/components/huisbaasje/sensor.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33

44
import logging
55

6-
from homeassistant.components.sensor import SensorEntity, SensorStateClass
6+
from homeassistant.components.sensor import (
7+
SensorDeviceClass,
8+
SensorEntity,
9+
SensorStateClass,
10+
)
711
from homeassistant.config_entries import ConfigEntry
812
from homeassistant.const import CONF_ID, POWER_WATT
913
from homeassistant.core import HomeAssistant
@@ -42,7 +46,7 @@ def __init__(
4246
user_id: str,
4347
name: str,
4448
source_type: str,
45-
device_class: str | None = None,
49+
device_class: SensorDeviceClass | None = None,
4650
sensor_type: str = SENSOR_TYPE_RATE,
4751
unit_of_measurement: str = POWER_WATT,
4852
icon: str = "mdi:lightning-bolt",
@@ -72,7 +76,7 @@ def name(self) -> str:
7276
return self._name
7377

7478
@property
75-
def device_class(self) -> str | None:
79+
def device_class(self) -> SensorDeviceClass | None:
7680
"""Return the device class of the sensor."""
7781
return self._device_class
7882

homeassistant/components/iaqualink/sensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def native_value(self) -> int | float | None:
5454
return float(self.dev.state)
5555

5656
@property
57-
def device_class(self) -> str | None:
57+
def device_class(self) -> SensorDeviceClass | None:
5858
"""Return the class of the sensor."""
5959
if self.dev.name.endswith("_temp"):
6060
return SensorDeviceClass.TEMPERATURE

homeassistant/components/neato/sensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def unique_id(self) -> str:
7979
return self._robot_serial
8080

8181
@property
82-
def device_class(self) -> str:
82+
def device_class(self) -> SensorDeviceClass:
8383
"""Return the device class."""
8484
return SensorDeviceClass.BATTERY
8585

homeassistant/components/nina/binary_sensor.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ def __init__(
6262
"""Initialize."""
6363
super().__init__(coordinator)
6464

65-
self._region: str = region
66-
self._warning_index: int = slot_id - 1
65+
self._region = region
66+
self._warning_index = slot_id - 1
6767

68-
self._attr_name: str = f"Warning: {region_name} {slot_id}"
69-
self._attr_unique_id: str = f"{region}-{slot_id}"
70-
self._attr_device_class: str = BinarySensorDeviceClass.SAFETY
68+
self._attr_name = f"Warning: {region_name} {slot_id}"
69+
self._attr_unique_id = f"{region}-{slot_id}"
70+
self._attr_device_class = BinarySensorDeviceClass.SAFETY
7171

7272
@property
7373
def is_on(self) -> bool:

0 commit comments

Comments
 (0)