Skip to content

Commit 96ab27a

Browse files
authored
Merge pull request #59 from ChristophCaina/merge-to-source
deprication fixes, bump Surepy, Changed file-structure
2 parents 77ff2da + 3caab7e commit 96ab27a

File tree

13 files changed

+82
-35
lines changed

13 files changed

+82
-35
lines changed

__init__.py renamed to custom_components/sureha/__init__.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import async_timeout
1010
from homeassistant.config_entries import ConfigEntry
11-
from homeassistant.const import CONF_PASSWORD, CONF_TOKEN, CONF_USERNAME
11+
from homeassistant.const import CONF_PASSWORD, CONF_TOKEN, CONF_USERNAME, Platform
1212
from homeassistant.core import HomeAssistant
1313
from homeassistant.exceptions import ConfigEntryAuthFailed
1414
from homeassistant.helpers import config_validation as cv
@@ -39,7 +39,7 @@
3939

4040
_LOGGER = logging.getLogger(__name__)
4141

42-
PLATFORMS = ["binary_sensor", "device_tracker", "sensor"]
42+
PLATFORMS = [Platform.BINARY_SENSOR, Platform.DEVICE_TRACKER, Platform.SENSOR]
4343
SCAN_INTERVAL = timedelta(minutes=3)
4444

4545
CONFIG_SCHEMA = vol.Schema(
@@ -179,23 +179,7 @@ async def async_setup(self) -> bool:
179179
_LOGGER.info(" \x1b[38;2;255;26;102m·\x1b[0m" * 30)
180180
_LOGGER.info("")
181181

182-
self.hass.async_add_job(
183-
self.hass.config_entries.async_forward_entry_setup( # type: ignore
184-
self.config_entry, "binary_sensor"
185-
)
186-
)
187-
188-
self.hass.async_add_job(
189-
self.hass.config_entries.async_forward_entry_setup( # type: ignore
190-
self.config_entry, "sensor"
191-
)
192-
)
193-
194-
self.hass.async_add_job(
195-
self.hass.config_entries.async_forward_entry_setup( # type: ignore
196-
self.config_entry, "device_tracker"
197-
)
198-
)
182+
await self.hass.config_entries.async_forward_entry_setups(self.config_entry, PLATFORMS)
199183

200184
surepy_entities: list[SurepyEntity] = self.coordinator.data.values()
201185

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
from typing import Any
55

66
from homeassistant.components.binary_sensor import (
7-
DEVICE_CLASS_CONNECTIVITY,
8-
DEVICE_CLASS_PRESENCE,
7+
BinarySensorDeviceClass,
98
BinarySensorEntity,
109
)
1110
from homeassistant.config_entries import ConfigEntry
@@ -151,7 +150,7 @@ class Hub(SurePetcareBinarySensor):
151150

152151
def __init__(self, coordinator, _id: int, spc: SurePetcareAPI) -> None:
153152
"""Initialize a Sure Petcare Hub."""
154-
super().__init__(coordinator, _id, spc, DEVICE_CLASS_CONNECTIVITY)
153+
super().__init__(coordinator, _id, spc, BinarySensorDeviceClass.CONNECTIVITY)
155154

156155
if self._attr_device_info:
157156
self._attr_device_info["identifiers"] = {(DOMAIN, str(self._id))}
@@ -183,7 +182,7 @@ class Pet(SurePetcareBinarySensor):
183182
def __init__(self, coordinator, _id: int, spc: SurePetcareAPI) -> None:
184183
"""Initialize a Sure Petcare Pet."""
185184

186-
super().__init__(coordinator, _id, spc, DEVICE_CLASS_PRESENCE)
185+
super().__init__(coordinator, _id, spc, BinarySensorDeviceClass.PRESENCE)
187186

188187
# explicit typing
189188
self._surepy_entity: SurePet
@@ -227,7 +226,7 @@ class DeviceConnectivity(SurePetcareBinarySensor):
227226
def __init__(self, coordinator, _id: int, spc: SurePetcareAPI) -> None:
228227
"""Initialize a Sure Petcare device connectivity sensor."""
229228

230-
super().__init__(coordinator, _id, spc, DEVICE_CLASS_CONNECTIVITY)
229+
super().__init__(coordinator, _id, spc, BinarySensorDeviceClass.CONNECTIVITY)
231230

232231
self._attr_name = f"{self._name} Connectivity"
233232
self._attr_unique_id = (

device_tracker.py renamed to custom_components/sureha/device_tracker.py

File renamed without changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"issue_tracker": "https://github.com/benleb/sureha/issues",
77
"config_flow": true,
88
"codeowners": ["@benleb"],
9-
"requirements": ["surepy>=0.7.2"],
9+
"requirements": ["surepy>=0.9.0"],
1010
"iot_class": "cloud_polling"
11-
}
11+
}

sensor.py renamed to custom_components/sureha/sensor.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33

44
from typing import Any, cast
55

6-
from homeassistant.components.sensor import SensorEntity
6+
from homeassistant.components.sensor import (
7+
SensorEntity,
8+
SensorDeviceClass,
9+
)
710
from homeassistant.config_entries import ConfigEntry
811
from homeassistant.const import (
912
ATTR_VOLTAGE,
10-
DEVICE_CLASS_BATTERY,
11-
MASS_GRAMS,
13+
UnitOfMass,
1214
PERCENTAGE,
13-
VOLUME_MILLILITERS,
15+
UnitOfVolume,
1416
)
1517
from homeassistant.core import HomeAssistant
1618
from homeassistant.helpers.update_coordinator import CoordinatorEntity
@@ -217,7 +219,7 @@ def __init__(self, coordinator, _id: int, spc: SurePetcareAPI):
217219
self._surepy_entity: SureFelaqua
218220

219221
self._attr_entity_picture = self._surepy_entity.icon
220-
self._attr_unit_of_measurement = VOLUME_MILLILITERS
222+
self._attr_unit_of_measurement = UnitOfVolume.MILLILITERS
221223

222224
@property
223225
def state(self) -> float | None:
@@ -263,7 +265,7 @@ def __init__(
263265
self._attr_unique_id = (
264266
f"{self._surepy_feeder_entity.household_id}-{self.feeder_id}-{self.bowl_id}"
265267
)
266-
self._attr_unit_of_measurement = MASS_GRAMS
268+
self._attr_unit_of_measurement = UnitOfMass.GRAMS
267269

268270
@property
269271
def state(self) -> float | None:
@@ -284,7 +286,7 @@ def __init__(self, coordinator, _id: int, spc: SurePetcareAPI):
284286
self._surepy_entity: SureFeeder
285287

286288
self._attr_entity_picture = self._surepy_entity.icon
287-
self._attr_unit_of_measurement = MASS_GRAMS
289+
self._attr_unit_of_measurement = UnitOfMass.GRAMS
288290

289291
@property
290292
def state(self) -> float | None:
@@ -314,7 +316,7 @@ def __init__(
314316
self.voltage_full = voltage_full
315317

316318
self._attr_unit_of_measurement = PERCENTAGE
317-
self._attr_device_class = DEVICE_CLASS_BATTERY
319+
self._attr_device_class = SensorDeviceClass.BATTERY
318320
self._attr_unique_id = (
319321
f"{self._surepy_entity.household_id}-{self._surepy_entity.id}-battery"
320322
)
@@ -326,6 +328,8 @@ def state(self) -> int | None:
326328
if battery := cast(SurepyDevice, self._coordinator.data[self._id]):
327329

328330
self._surepy_entity = battery
331+
self.device_class = SensorDeviceClass.BATTERY
332+
self.native_unit_of_measurement=PERCENTAGE
329333
battery_level = battery.calculate_battery_level(
330334
voltage_full=self.voltage_full, voltage_low=self.voltage_low
331335
)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"config": {
3+
"error": {
4+
"invalid_auth": "Ungültige Authentifizierung",
5+
"unknown": "Unerwarteter Fehler"
6+
},
7+
"step": {
8+
"user": {
9+
"data": {
10+
"password": "Passwort",
11+
"username": "Benutzername"
12+
},
13+
"description": "Mit dem Sure Petcare Konto anmelden.",
14+
"title": "Sure Petcare"
15+
}
16+
}
17+
},
18+
"options": {
19+
"step": {
20+
"init": {
21+
"data": {
22+
"voltage_full": "Volt (Batterien voll)",
23+
"voltage_low": "Volt (Batterien leer)"
24+
},
25+
"description": "Batterie Optionen",
26+
"title": "SureHA Opptionen"
27+
}
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)