Skip to content

Commit

Permalink
Mypy cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaskistler committed May 3, 2024
1 parent 10aa99e commit f86a0d2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
6 changes: 1 addition & 5 deletions homeassistant/components/hydrawise/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

from __future__ import annotations

from typing import Any

from pydrawise import Sensor, Zone

from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
Expand Down Expand Up @@ -86,7 +82,7 @@ def _update_attrs(self) -> None:
def _get_status(self) -> bool:
return self.coordinator.last_update_success

def _get_rain_sensor(self) -> Any:
def _get_rain_sensor(self) -> bool | None:
assert self.sensor is not None
return self.sensor.status.active

Expand Down
13 changes: 5 additions & 8 deletions homeassistant/components/hydrawise/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
from __future__ import annotations

from datetime import datetime
from typing import Any

from pydrawise import Zone

from homeassistant.components.sensor import (
SensorDeviceClass,
Expand Down Expand Up @@ -109,8 +106,6 @@ async def async_setup_entry(
class HydrawiseSensor(HydrawiseEntity, SensorEntity):
"""A sensor implementation for Hydrawise device."""

zone: Zone

@property
def icon(self) -> str | None:
"""Icon of the entity based on the value."""
Expand All @@ -123,16 +118,18 @@ def _update_attrs(self) -> None:
self._attr_native_value = getattr(self, f"_get_{self.entity_description.key}")()

def _get_watering_time(self) -> int:
assert self.zone is not None
if (current_run := self.zone.scheduled_runs.current_run) is not None:
return int(current_run.remaining_time.total_seconds() / 60)
return 0

def _get_next_cycle(self) -> datetime:
assert self.zone is not None
if (next_run := self.zone.scheduled_runs.next_run) is not None:
return dt_util.as_utc(next_run.start_time)
return datetime.max.replace(tzinfo=dt_util.UTC)

def _get_daily_active_water_use(self) -> Any:
def _get_daily_active_water_use(self) -> float:
daily_water_summary = self.coordinator.data.daily_water_use[self.controller.id]
if self.zone is not None:
# water use for the zone
Expand All @@ -144,7 +141,7 @@ def _get_daily_active_water_use(self) -> Any:
return daily_water_summary.total_active_use
return 0.0 # pragma: no cover

def _get_daily_inactive_water_use(self) -> Any:
def _get_daily_inactive_water_use(self) -> float | None:
if self.zone is None and self.sensor is not None:
# water use for the controller
daily_water_summary = self.coordinator.data.daily_water_use[
Expand All @@ -153,7 +150,7 @@ def _get_daily_inactive_water_use(self) -> Any:
return daily_water_summary.total_inactive_use
return None # pragma: no cover

def _get_daily_total_water_use(self) -> Any:
def _get_daily_total_water_use(self) -> float | None:
if self.zone is None and self.sensor is not None:
# water use for the controller
daily_water_summary = self.coordinator.data.daily_water_use[
Expand Down

0 comments on commit f86a0d2

Please sign in to comment.