Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
Fix all pyright errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Prior99 committed Sep 10, 2024
1 parent 021c4f6 commit 9dda079
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 161 deletions.
2 changes: 1 addition & 1 deletion Justfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
lint:
poetry run ruff check .
poetry run ruff format . --diff
poetry run mypy .
poetry run pyright

8 changes: 4 additions & 4 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from datetime import timedelta
import logging
from typing import overload

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
Expand Down Expand Up @@ -76,9 +75,10 @@ async def async_login(self) -> bool:
self.config.data["email"], self.config.data["password"]
)

async def _async_update_data(self) -> list[Vehicle]:
return await self.hub.get_all_vehicles()
async def _async_update_data(self) -> dict[str, list[Vehicle]]:
return {
"vehicles": await self.hub.get_all_vehicles(),
}

@overload
def _unsub_refresh(self):
return
43 changes: 14 additions & 29 deletions binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Binary Sensors for MySkoda."""

from typing import overload

from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
Expand All @@ -28,7 +26,7 @@ async def async_setup_entry(
"""Set up the sensor platform."""
coordinator = hass.data[DOMAIN][config.entry_id][DATA_COODINATOR]

vehicles = coordinator.data
vehicles = coordinator.data.get("vehicles")

entities = []

Expand Down Expand Up @@ -75,8 +73,7 @@ def __init__(self, coordinator: DataUpdateCoordinator, vehicle: Vehicle) -> None
self._attr_unique_id = f"{vehicle.info.vin}_charger_connected"

@property
@overload
def is_on(self):
def is_on(self): # noqa: D102
if not self.coordinator.data:
return None

Expand All @@ -85,8 +82,7 @@ def is_on(self):
return self.vehicle.air_conditioning.charger_connected

@property
@overload
def icon(self):
def icon(self): # noqa: D102
if not self.coordinator.data:
return "mdi:power_plug"

Expand All @@ -113,8 +109,7 @@ def __init__(self, coordinator: DataUpdateCoordinator, vehicle: Vehicle) -> None
self._attr_unique_id = f"{vehicle.info.vin}_charger_locked"

@property
@overload
def is_on(self):
def is_on(self): # noqa: D102
if not self.coordinator.data:
return None

Expand All @@ -123,8 +118,7 @@ def is_on(self):
return not self.vehicle.air_conditioning.charger_locked

@property
@overload
def icon(self):
def icon(self): # noqa: D102
if not self.coordinator.data:
return "mdi:lock"

Expand All @@ -151,8 +145,7 @@ def __init__(self, coordinator: DataUpdateCoordinator, vehicle: Vehicle) -> None
self._attr_unique_id = f"{vehicle.info.vin}_locked"

@property
@overload
def is_on(self):
def is_on(self): # noqa: D102
if not self.coordinator.data:
return None

Expand All @@ -161,8 +154,7 @@ def is_on(self):
return not self.vehicle.status.locked

@property
@overload
def icon(self):
def icon(self): # noqa: D102
if not self.coordinator.data:
return "mdi:lock"

Expand All @@ -189,8 +181,7 @@ def __init__(self, coordinator: DataUpdateCoordinator, vehicle: Vehicle) -> None
self._attr_unique_id = f"{vehicle.info.vin}_doors_locked"

@property
@overload
def is_on(self):
def is_on(self): # noqa: D102
if not self.coordinator.data:
return None

Expand All @@ -199,8 +190,7 @@ def is_on(self):
return not self.vehicle.status.doors_locked

@property
@overload
def icon(self):
def icon(self): # noqa: D102
if not self.coordinator.data:
return "mdi:lock"

Expand Down Expand Up @@ -228,8 +218,7 @@ def __init__(self, coordinator: DataUpdateCoordinator, vehicle: Vehicle) -> None
self._attr_unique_id = f"{vehicle.info.vin}_doors_open"

@property
@overload
def is_on(self):
def is_on(self): # noqa: D102
if not self.coordinator.data:
return None

Expand All @@ -255,8 +244,7 @@ def __init__(self, coordinator: DataUpdateCoordinator, vehicle: Vehicle) -> None
self._attr_unique_id = f"{vehicle.info.vin}_windows_open"

@property
@overload
def is_on(self):
def is_on(self): # noqa: D102
if not self.coordinator.data:
return None

Expand All @@ -282,8 +270,7 @@ def __init__(self, coordinator: DataUpdateCoordinator, vehicle: Vehicle) -> None
self._attr_unique_id = f"{vehicle.info.vin}_trunk_open"

@property
@overload
def is_on(self):
def is_on(self): # noqa: D102
if not self.coordinator.data:
return None

Expand All @@ -309,8 +296,7 @@ def __init__(self, coordinator: DataUpdateCoordinator, vehicle: Vehicle) -> None
self._attr_unique_id = f"{vehicle.info.vin}_bonnet_open"

@property
@overload
def is_on(self):
def is_on(self): # noqa: D102
if not self.coordinator.data:
return None

Expand All @@ -336,8 +322,7 @@ def __init__(self, coordinator: DataUpdateCoordinator, vehicle: Vehicle) -> None
self._attr_unique_id = f"{vehicle.info.vin}_lights_on"

@property
@overload
def is_on(self):
def is_on(self): # noqa: D102
if not self.coordinator.data:
return None

Expand Down
19 changes: 7 additions & 12 deletions climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from asyncio import sleep
import logging
from typing import overload

from homeassistant.components.climate import (
ClimateEntity,
Expand Down Expand Up @@ -34,7 +33,7 @@ async def async_setup_entry(
"""Set up the sensor platform."""
coordinator = hass.data[DOMAIN][config.entry_id][DATA_COODINATOR]

vehicles = coordinator.data
vehicles = coordinator.data.get("vehicles")

entities = [MySkodaClimate(coordinator, vehicle) for vehicle in vehicles]

Expand Down Expand Up @@ -64,13 +63,11 @@ def __init__(self, coordinator: DataUpdateCoordinator, vehicle: Vehicle) -> None
self._attr_unique_id = f"{self.vehicle.info.vin}_climate"

@property
@overload
def hvac_modes(self) -> list[HVACMode]:
def hvac_modes(self) -> list[HVACMode]: # noqa: D102
return [HVACMode.AUTO, HVACMode.OFF]

@property
@overload
def hvac_mode(self) -> HVACMode | None:
def hvac_mode(self) -> HVACMode | None: # noqa: D102
if not self.coordinator.data:
return None

Expand All @@ -81,8 +78,7 @@ def hvac_mode(self) -> HVACMode | None:
return HVACMode.OFF

@property
@overload
def hvac_action(self) -> HVACAction | None:
def hvac_action(self) -> HVACAction | None: # noqa: D102
if not self.coordinator.data:
return None

Expand All @@ -95,8 +91,7 @@ def hvac_action(self) -> HVACAction | None:
return HVACAction.OFF

@property
@overload
def target_temperature(self) -> None | float:
def target_temperature(self) -> None | float: # noqa: D102
if not self.coordinator.data:
return None

Expand All @@ -120,10 +115,10 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode): # noqa: D102
_LOGGER.info("HVAC mode set to %s.", hvac_mode)

async def async_turn_on(self): # noqa: D102
await self.set_hvac_mode(HVACMode.AUTO)
await self.async_set_hvac_mode(HVACMode.AUTO)

async def async_turn_off(self): # noqa: D102
await self.set_hvac_mode(HVACMode.OFF)
await self.async_set_hvac_mode(HVACMode.OFF)

async def async_set_temperature(self, **kwargs): # noqa: D102
temp = kwargs[ATTR_TEMPERATURE]
Expand Down
7 changes: 3 additions & 4 deletions config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

import voluptuous as vol

from homeassistant import config_entries
from homeassistant.config_entries import ConfigFlow as BaseConfigFlow, ConfigFlowResult
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResult
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.aiohttp_client import async_get_clientsession

Expand All @@ -34,14 +33,14 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> None:
raise InvalidAuth


class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
class ConfigFlow(BaseConfigFlow, domain=DOMAIN):
"""Handle a config flow for MySkoda."""

VERSION = 1

async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
) -> ConfigFlowResult:
"""Handle the initial step."""
if user_input is None:
return self.async_show_form(
Expand Down
13 changes: 4 additions & 9 deletions device_tracker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Device Tracker entities for MySkoda."""

from typing import overload

from homeassistant.components.device_tracker.config_entry import TrackerEntity
from homeassistant.components.device_tracker.const import SourceType
from homeassistant.config_entries import ConfigEntry
Expand All @@ -25,7 +23,7 @@ async def async_setup_entry(
"""Set up the sensor platform."""
coordinator = hass.data[DOMAIN][config.entry_id][DATA_COODINATOR]

vehicles = coordinator.data
vehicles = coordinator.data.get("vehicles")

entities = [DeviceTracker(coordinator, vehicle) for vehicle in vehicles]

Expand All @@ -48,13 +46,11 @@ def __init__(self, coordinator: DataUpdateCoordinator, vehicle: Vehicle) -> None
)

@property
@overload
def source_type(self) -> SourceType:
def source_type(self) -> SourceType: # noqa: D102
return SourceType.GPS

@property
@overload
def latitude(self) -> float | None:
def latitude(self) -> float | None: # noqa: D102
if not self.coordinator.data:
return None

Expand All @@ -63,8 +59,7 @@ def latitude(self) -> float | None:
return self.vehicle.position.lat

@property
@overload
def longitude(self) -> float | None:
def longitude(self) -> float | None: # noqa: D102
if not self.coordinator.data:
return None

Expand Down
7 changes: 2 additions & 5 deletions entity.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""MySkoda Entity base classes."""

from typing import overload

from homeassistant.helpers.entity import DeviceInfo, Entity, EntityDescription
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
Expand All @@ -23,8 +21,7 @@ def __init__(self, vehicle: Vehicle, entity_description: EntityDescription) -> N
self.entity_description = entity_description

@property
@overload
def device_info(self) -> DeviceInfo:
def device_info(self) -> DeviceInfo: # noqa: D102
return {
"identifiers": {(DOMAIN, self.vehicle.info.vin)},
"name": self.vehicle.info.title,
Expand All @@ -48,7 +45,7 @@ def __init__( # noqa: D107
MySkodaEntity.__init__(self, vehicle, entity_description)

def _update_device_from_coordinator(self) -> None:
for vehicle in self.coordinator.data:
for vehicle in self.coordinator.data.get("vehicles"):
if vehicle.info.vin == self.vehicle.info.vin:
self.vehicle = vehicle
return
6 changes: 2 additions & 4 deletions number.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from asyncio import sleep
import logging
from typing import overload

from homeassistant.components.number import (
NumberDeviceClass,
Expand Down Expand Up @@ -32,7 +31,7 @@ async def async_setup_entry(
"""Set up the sensor platform."""
coordinator = hass.data[DOMAIN][config.entry_id][DATA_COODINATOR]

vehicles = coordinator.data
vehicles = coordinator.data.get("vehicles")

entities = [ChargeLimit(coordinator, vehicle) for vehicle in vehicles]

Expand Down Expand Up @@ -83,8 +82,7 @@ def __init__(self, coordinator: DataUpdateCoordinator, vehicle: Vehicle) -> None
self._attr_device_class = NumberDeviceClass.BATTERY

@property
@overload
def native_value(self) -> float | None:
def native_value(self) -> float | None: # noqa: D102
if not self.coordinator.data:
return None

Expand Down
Loading

0 comments on commit 9dda079

Please sign in to comment.