Skip to content

Commit 9ab074f

Browse files
committed
Styling/typing
1 parent 69c4330 commit 9ab074f

15 files changed

Lines changed: 79 additions & 64 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
## Changelog
44

5-
### DEC 2023 [0.3.0]
5+
### DEC 2023 [0.3.1 (alpha/beta]
6+
7+
- Released version 0.3
8+
9+
### DEC 2023 [0.3.0 (alpha/beta]
610

711
- Introduce Lock and Light switches
812
- Fix UnitOf[X] for future HA compatibility (e.g. TEMP_CELSIUS => UnitOfTemperature.CELSIUS)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ In the current state it retrieves `bike`, `status` and `position` from the API e
3131
**BETA** There is an early implementation on toggling data on your bike, `light` and `lock` can be adjusted.
3232
Do note that the switches do not immediately reflect the status (i.e. they will when you toggle them, but switch back quickly).
3333
After your 'switch' command we do request an API update to check on the status, pending that update the switch might toggle back-n-forth some time.
34+
The light-switch is called 'Light mode' as depending on your bike type it will switch on/off or between 'dim and bright'.
3435

3536
## If you want more frequent updates
3637

custom_components/stromer/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
4646
hass.config_entries.async_update_entry(entry, unique_id=stromer.bike_id)
4747

4848
# Set up coordinator for fetching data
49-
coordinator = StromerDataUpdateCoordinator(hass, stromer, SCAN_INTERVAL)
49+
coordinator = StromerDataUpdateCoordinator(hass, stromer, SCAN_INTERVAL) # type: ignore[arg-type]
5050
await coordinator.async_config_entry_first_refresh()
5151

5252
# Store coordinator for use in platforms
@@ -73,4 +73,4 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
7373
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
7474
hass.data[DOMAIN].pop(entry.entry_id)
7575

76-
return unload_ok
76+
return unload_ok # type: ignore [no-any-return]

custom_components/stromer/binary_sensor.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33

44
from dataclasses import dataclass
55

6-
from custom_components.stromer.coordinator import StromerDataUpdateCoordinator
7-
86
from homeassistant.components.binary_sensor import (
97
BinarySensorEntity,
108
BinarySensorEntityDescription,
119
)
10+
from homeassistant.config_entries import ConfigEntry
11+
from homeassistant.core import HomeAssistant
1212
from homeassistant.helpers.entity import EntityCategory
13+
from homeassistant.helpers.entity_platform import AddEntitiesCallback
1314

1415
from .const import DOMAIN, LOGGER
16+
from .coordinator import StromerDataUpdateCoordinator
1517
from .entity import StromerEntity
1618

1719

1820
@dataclass
19-
class StromerBinarySensorEntityDescription(BinarySensorEntityDescription):
21+
class StromerBinarySensorEntityDescription(BinarySensorEntityDescription): # type: ignore[misc]
2022
"""Describes a Stromer binary sensor entity."""
2123

2224
icon_off: str | None = None
@@ -47,7 +49,7 @@ class StromerBinarySensorEntityDescription(BinarySensorEntityDescription):
4749
)
4850

4951

50-
async def async_setup_entry(hass, config_entry, async_add_entities):
52+
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback) -> None:
5153
"""Set up the Stromer sensors from a config entry."""
5254
coordinator = hass.data[DOMAIN][config_entry.entry_id]
5355

@@ -65,7 +67,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
6567
async_add_entities(entities, update_before_add=False)
6668

6769

68-
class StromerBinarySensor(StromerEntity, BinarySensorEntity):
70+
class StromerBinarySensor(StromerEntity, BinarySensorEntity): # type: ignore[misc]
6971
"""Representation of a Binary Sensor."""
7072

7173
_attr_has_entity_name = True
@@ -92,4 +94,4 @@ def __init__(
9294
@property
9395
def is_on(self) -> bool | None:
9496
"""Return true if the binary sensor is on."""
95-
return self._coordinator.data.bikedata.get(self._ent)
97+
return self._coordinator.data.bikedata.get(self._ent) # type: ignore[no-any-return]

custom_components/stromer/config_flow.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from homeassistant import config_entries
99
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
10+
from homeassistant.core import HomeAssistant
1011
from homeassistant.data_entry_flow import FlowResult
1112
from homeassistant.exceptions import HomeAssistantError
1213

@@ -23,7 +24,7 @@
2324
)
2425

2526

26-
async def validate_input(_, data: dict[str, Any]) -> dict[str, Any]:
27+
async def validate_input(_: HomeAssistant, data: dict[str, Any]) -> dict[str, Any]:
2728
"""Validate the user input allows us to connect."""
2829
username = data[CONF_USERNAME]
2930
password = data[CONF_PASSWORD]
@@ -39,7 +40,7 @@ async def validate_input(_, data: dict[str, Any]) -> dict[str, Any]:
3940
return {"title": stromer.bike_name}
4041

4142

42-
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
43+
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): # type: ignore[call-arg, misc]
4344
"""Handle a config flow for Stromer."""
4445

4546
VERSION = 1
@@ -75,9 +76,9 @@ async def async_step_user(
7576
)
7677

7778

78-
class CannotConnect(HomeAssistantError):
79+
class CannotConnect(HomeAssistantError): # type: ignore[misc]
7980
"""Error to indicate we cannot connect."""
8081

8182

82-
class InvalidAuth(HomeAssistantError):
83+
class InvalidAuth(HomeAssistantError): # type: ignore[misc]
8384
"""Error to indicate there is invalid auth."""

custom_components/stromer/coordinator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class StromerData(NamedTuple):
1717
bike_name: str
1818

1919

20-
class StromerDataUpdateCoordinator(DataUpdateCoordinator[StromerData]):
20+
class StromerDataUpdateCoordinator(DataUpdateCoordinator[StromerData]): # type: ignore[misc]
2121
"""Class to manage fetching Stromer data from single endpoint."""
2222

2323
def __init__(self, hass: HomeAssistant, stromer: Stromer, interval: float) -> None:
@@ -45,4 +45,4 @@ async def _async_update_data(self) -> StromerData:
4545
raise UpdateFailed(f"Error communicating with API: {err}") from err
4646
except Exception as err:
4747
raise ConfigEntryAuthFailed from err
48-
return StromerData(*data)
48+
return StromerData(*data) # type: ignore [arg-type]

custom_components/stromer/device_tracker.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
"""Stromer binary sensor component for Home Assistant."""
22
from __future__ import annotations
33

4-
from custom_components.stromer.coordinator import StromerDataUpdateCoordinator
5-
64
from homeassistant.components.device_tracker import SourceType, TrackerEntity
5+
from homeassistant.config_entries import ConfigEntry
6+
from homeassistant.core import HomeAssistant
77
from homeassistant.helpers.entity import EntityCategory
8+
from homeassistant.helpers.entity_platform import AddEntitiesCallback
89

910
from .const import DOMAIN
11+
from .coordinator import StromerDataUpdateCoordinator
1012
from .entity import StromerEntity
1113

1214

13-
async def async_setup_entry(hass, config_entry, async_add_entities):
15+
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback) -> None:
1416
"""Set up the Stromer sensors from a config entry."""
1517
coordinator = hass.data[DOMAIN][config_entry.entry_id]
1618

1719
async_add_entities([StromerTracker(coordinator)], update_before_add=False)
1820

1921

20-
class StromerTracker(StromerEntity, TrackerEntity):
22+
class StromerTracker(StromerEntity, TrackerEntity): # type: ignore[misc]
2123
"""Representation of a Device Tracker."""
2224

2325
def __init__(
@@ -43,9 +45,9 @@ def source_type(self) -> SourceType | str:
4345
@property
4446
def latitude(self) -> float | None:
4547
"""Return latitude value of the device."""
46-
return self._coordinator.data.bikedata.get("latitude")
48+
return float(self._coordinator.data.bikedata.get("latitude"))
4749

4850
@property
4951
def longitude(self) -> float | None:
5052
"""Return longitude value of the device."""
51-
return self._coordinator.data.bikedata.get("longitude")
53+
return float(self._coordinator.data.bikedata.get("longitude"))

custom_components/stromer/entity.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from .coordinator import StromerData, StromerDataUpdateCoordinator
1212

1313

14-
class StromerEntity(CoordinatorEntity[StromerData]):
14+
class StromerEntity(CoordinatorEntity[StromerData]): # type:ignore [misc]
1515
"""Represent a Stromer Entity."""
1616

1717
coordinator: StromerDataUpdateCoordinator
@@ -55,12 +55,12 @@ def __init__(
5555
@property
5656
def available(self) -> bool:
5757
"""Return if entity is available."""
58-
return super().available
58+
return super().available # type: ignore[no-any-return]
5959

6060
@property
6161
def device(self) -> dict[str, Any]:
6262
"""Return data for this device."""
63-
return self.coordinator.data.bike_id
63+
return self.coordinator.data.bike_id # type: ignore[no-any-return]
6464

6565
async def async_added_to_hass(self) -> None:
6666
"""Subscribe to updates."""

custom_components/stromer/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
"iot_class": "cloud_polling",
99
"issue_tracker": "https://github.com/CoMPaTech/stromer/issues",
1010
"requirements": [],
11-
"version": "0.3.0b1"
11+
"version": "0.3.1"
1212
}

custom_components/stromer/sensor.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
from __future__ import annotations
33

44
from datetime import UTC, datetime
5-
6-
from custom_components.stromer.coordinator import StromerDataUpdateCoordinator
5+
from typing import Any
76

87
from homeassistant.components.sensor import (
98
SensorDeviceClass,
109
SensorEntity,
1110
SensorEntityDescription,
1211
SensorStateClass,
1312
)
13+
from homeassistant.config_entries import ConfigEntry
1414
from homeassistant.const import (
1515
PERCENTAGE,
1616
UnitOfEnergy,
@@ -20,9 +20,12 @@
2020
UnitOfTemperature,
2121
UnitOfTime,
2222
)
23+
from homeassistant.core import HomeAssistant
2324
from homeassistant.helpers.entity import EntityCategory
25+
from homeassistant.helpers.entity_platform import AddEntitiesCallback
2426

2527
from .const import DOMAIN, LOGGER
28+
from .coordinator import StromerDataUpdateCoordinator
2629
from .entity import StromerEntity
2730

2831
SENSORS: tuple[SensorEntityDescription, ...] = (
@@ -169,7 +172,7 @@
169172
)
170173

171174

172-
async def async_setup_entry(hass, config_entry, async_add_entities):
175+
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback) -> None:
173176
"""Set up the Stromer sensors from a config entry."""
174177
coordinator = hass.data[DOMAIN][config_entry.entry_id]
175178

@@ -183,7 +186,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
183186
async_add_entities(entities, update_before_add=False)
184187

185188

186-
class StromerSensor(StromerEntity, SensorEntity):
189+
class StromerSensor(StromerEntity, SensorEntity): # type: ignore[misc]
187190
"""Representation of a Sensor."""
188191

189192
_attr_has_entity_name = True
@@ -220,7 +223,7 @@ def _ensure_timezone(timestamp: datetime | None) -> datetime | None:
220223
return timestamp
221224

222225
@property
223-
def native_value(self):
226+
def native_value(self) -> Any:
224227
"""Return the state of the sensor."""
225228
if self.entity_description.device_class == SensorDeviceClass.TIMESTAMP:
226229
return self._ensure_timezone(

0 commit comments

Comments
 (0)