Typing improvements (#120297)

This commit is contained in:
Marc Mueller 2024-06-24 11:07:22 +02:00 committed by GitHub
parent 158c8b8400
commit be6dfc7a70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 12 additions and 12 deletions

View file

@ -331,7 +331,7 @@ class FritzBoxBaseSwitch(FritzBoxBaseEntity, SwitchEntity):
self._name = f"{self._friendly_name} {self._description}"
self._unique_id = f"{self._avm_wrapper.unique_id}-{slugify(self._description)}"
self._attributes: dict[str, str] = {}
self._attributes: dict[str, str | None] = {}
self._is_available = True
@property
@ -355,7 +355,7 @@ class FritzBoxBaseSwitch(FritzBoxBaseEntity, SwitchEntity):
return self._is_available
@property
def extra_state_attributes(self) -> dict[str, str]:
def extra_state_attributes(self) -> dict[str, str | None]:
"""Return device attributes."""
return self._attributes

View file

@ -85,7 +85,7 @@ class GeniusBattery(GeniusDevice, SensorEntity):
return icon
@property
def native_value(self) -> str:
def native_value(self) -> int:
"""Return the state of the sensor."""
level = self._device.data["state"][self._state_attr]
return level if level != 255 else 0

View file

@ -377,7 +377,7 @@ class HeosMediaPlayer(MediaPlayerEntity):
return self._media_position_updated_at
@property
def media_image_url(self) -> str:
def media_image_url(self) -> str | None:
"""Image url of current playing media."""
# May be an empty string, if so, return None
image_url = self._player.now_playing_media.image_url

View file

@ -119,7 +119,7 @@ class KeeneticTracker(ScannerEntity):
return f"{self._device.mac}_{self._router.config_entry.entry_id}"
@property
def ip_address(self) -> str:
def ip_address(self) -> str | None:
"""Return the primary ip address of the device."""
return self._device.ip if self.is_connected else None

View file

@ -332,6 +332,7 @@ class KNXCommonFlow(ABC, ConfigEntryBaseFlow):
self.initial_data.get(CONF_KNX_CONNECTION_TYPE)
in CONF_KNX_TUNNELING_TYPE_LABELS
)
ip_address: str | None
if ( # initial attempt on ConfigFlow or coming from automatic / routing
(isinstance(self, ConfigFlow) or not _reconfiguring_existing_tunnel)
and not user_input

View file

@ -56,7 +56,7 @@ class LovelaceConfig(ABC):
self.config = None
@property
def url_path(self) -> str:
def url_path(self) -> str | None:
"""Return url path."""
return self.config[CONF_URL_PATH] if self.config else None

View file

@ -74,7 +74,7 @@ class ModbusRegisterSensor(BaseStructPlatform, RestoreSensor, SensorEntity):
super().__init__(hass, hub, entry)
if slave_count:
self._count = self._count * (slave_count + 1)
self._coordinator: DataUpdateCoordinator[list[int] | None] | None = None
self._coordinator: DataUpdateCoordinator[list[float] | None] | None = None
self._attr_native_unit_of_measurement = entry.get(CONF_UNIT_OF_MEASUREMENT)
self._attr_state_class = entry.get(CONF_STATE_CLASS)
self._attr_device_class = entry.get(CONF_DEVICE_CLASS)
@ -142,7 +142,7 @@ class ModbusRegisterSensor(BaseStructPlatform, RestoreSensor, SensorEntity):
class SlaveSensor(
CoordinatorEntity[DataUpdateCoordinator[list[int] | None]],
CoordinatorEntity[DataUpdateCoordinator[list[float] | None]],
RestoreSensor,
SensorEntity,
):
@ -150,7 +150,7 @@ class SlaveSensor(
def __init__(
self,
coordinator: DataUpdateCoordinator[list[int] | None],
coordinator: DataUpdateCoordinator[list[float] | None],
idx: int,
entry: dict[str, Any],
) -> None:

View file

@ -84,9 +84,8 @@ class ZWaveMeRGB(ZWaveMeEntity, LightEntity):
self.device.id, f"exact?level={round(brightness / 2.55)}"
)
return
cmd = "exact?red={}&green={}&blue={}".format(
*color if any(color) else 255, 255, 255
)
cmd = "exact?red={}&green={}&blue={}"
cmd = cmd.format(*color) if any(color) else cmd.format(*(255, 255, 255))
self.controller.zwave_api.send_command(self.device.id, cmd)
@property