Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing improvements #120297

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions homeassistant/components/fritz/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def __init__(
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
Expand All @@ -355,7 +355,7 @@ def available(self) -> bool:
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

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/geniushub/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def icon(self) -> str:
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
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/heos/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def media_position_updated_at(self):
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
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/keenetic_ndms2/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def unique_id(self) -> str:
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

Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/knx/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ async def async_step_manual_tunnel(
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
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/lovelace/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(
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

Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/modbus/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(
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)
Expand Down Expand Up @@ -142,15 +142,15 @@ async def async_update(self, now: datetime | None = None) -> None:


class SlaveSensor(
CoordinatorEntity[DataUpdateCoordinator[list[int] | None]],
CoordinatorEntity[DataUpdateCoordinator[list[float] | None]],
RestoreSensor,
SensorEntity,
):
"""Modbus slave register sensor."""

def __init__(
self,
coordinator: DataUpdateCoordinator[list[int] | None],
coordinator: DataUpdateCoordinator[list[float] | None],
idx: int,
entry: dict[str, Any],
) -> None:
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/zwave_me/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,8 @@ def turn_on(self, **kwargs: Any) -> None:
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
Expand Down