Skip to content

Commit

Permalink
Merge pull request #59 from ChristophCaina/merge-to-source
Browse files Browse the repository at this point in the history
deprication fixes, bump Surepy, Changed file-structure
  • Loading branch information
benleb authored Jul 29, 2024
2 parents 77ff2da + 3caab7e commit 96ab27a
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 35 deletions.
22 changes: 3 additions & 19 deletions __init__.py → custom_components/sureha/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import async_timeout
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_PASSWORD, CONF_TOKEN, CONF_USERNAME
from homeassistant.const import CONF_PASSWORD, CONF_TOKEN, CONF_USERNAME, Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers import config_validation as cv
Expand Down Expand Up @@ -39,7 +39,7 @@

_LOGGER = logging.getLogger(__name__)

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

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

self.hass.async_add_job(
self.hass.config_entries.async_forward_entry_setup( # type: ignore
self.config_entry, "binary_sensor"
)
)

self.hass.async_add_job(
self.hass.config_entries.async_forward_entry_setup( # type: ignore
self.config_entry, "sensor"
)
)

self.hass.async_add_job(
self.hass.config_entries.async_forward_entry_setup( # type: ignore
self.config_entry, "device_tracker"
)
)
await self.hass.config_entries.async_forward_entry_setups(self.config_entry, PLATFORMS)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from typing import Any

from homeassistant.components.binary_sensor import (
DEVICE_CLASS_CONNECTIVITY,
DEVICE_CLASS_PRESENCE,
BinarySensorDeviceClass,
BinarySensorEntity,
)
from homeassistant.config_entries import ConfigEntry
Expand Down Expand Up @@ -151,7 +150,7 @@ class Hub(SurePetcareBinarySensor):

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

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

super().__init__(coordinator, _id, spc, DEVICE_CLASS_PRESENCE)
super().__init__(coordinator, _id, spc, BinarySensorDeviceClass.PRESENCE)

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

super().__init__(coordinator, _id, spc, DEVICE_CLASS_CONNECTIVITY)
super().__init__(coordinator, _id, spc, BinarySensorDeviceClass.CONNECTIVITY)

self._attr_name = f"{self._name} Connectivity"
self._attr_unique_id = (
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions manifest.json → custom_components/sureha/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"issue_tracker": "https://github.com/benleb/sureha/issues",
"config_flow": true,
"codeowners": ["@benleb"],
"requirements": ["surepy>=0.7.2"],
"requirements": ["surepy>=0.9.0"],
"iot_class": "cloud_polling"
}
}
20 changes: 12 additions & 8 deletions sensor.py → custom_components/sureha/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@

from typing import Any, cast

from homeassistant.components.sensor import SensorEntity
from homeassistant.components.sensor import (
SensorEntity,
SensorDeviceClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_VOLTAGE,
DEVICE_CLASS_BATTERY,
MASS_GRAMS,
UnitOfMass,
PERCENTAGE,
VOLUME_MILLILITERS,
UnitOfVolume,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import CoordinatorEntity
Expand Down Expand Up @@ -217,7 +219,7 @@ def __init__(self, coordinator, _id: int, spc: SurePetcareAPI):
self._surepy_entity: SureFelaqua

self._attr_entity_picture = self._surepy_entity.icon
self._attr_unit_of_measurement = VOLUME_MILLILITERS
self._attr_unit_of_measurement = UnitOfVolume.MILLILITERS

@property
def state(self) -> float | None:
Expand Down Expand Up @@ -263,7 +265,7 @@ def __init__(
self._attr_unique_id = (
f"{self._surepy_feeder_entity.household_id}-{self.feeder_id}-{self.bowl_id}"
)
self._attr_unit_of_measurement = MASS_GRAMS
self._attr_unit_of_measurement = UnitOfMass.GRAMS

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

self._attr_entity_picture = self._surepy_entity.icon
self._attr_unit_of_measurement = MASS_GRAMS
self._attr_unit_of_measurement = UnitOfMass.GRAMS

@property
def state(self) -> float | None:
Expand Down Expand Up @@ -314,7 +316,7 @@ def __init__(
self.voltage_full = voltage_full

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

self._surepy_entity = battery
self.device_class = SensorDeviceClass.BATTERY
self.native_unit_of_measurement=PERCENTAGE
battery_level = battery.calculate_battery_level(
voltage_full=self.voltage_full, voltage_low=self.voltage_low
)
Expand Down
File renamed without changes.
File renamed without changes.
30 changes: 30 additions & 0 deletions custom_components/sureha/translations/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"config": {
"error": {
"invalid_auth": "Ungültige Authentifizierung",
"unknown": "Unerwarteter Fehler"
},
"step": {
"user": {
"data": {
"password": "Passwort",
"username": "Benutzername"
},
"description": "Mit dem Sure Petcare Konto anmelden.",
"title": "Sure Petcare"
}
}
},
"options": {
"step": {
"init": {
"data": {
"voltage_full": "Volt (Batterien voll)",
"voltage_low": "Volt (Batterien leer)"
},
"description": "Batterie Optionen",
"title": "SureHA Opptionen"
}
}
}
}
File renamed without changes.
30 changes: 30 additions & 0 deletions custom_components/sureha/translations/nl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"config": {
"error": {
"invalid_auth": "Ongeldige authenticatie",
"unknown": "Onverwachte fout"
},
"step": {
"user": {
"data": {
"password": "Wachtwoord",
"username": "Gebruikersnaam"
},
"description": "Log in met je Sure Petcare account.",
"title": "Sure Petcare"
}
}
},
"options": {
"step": {
"init": {
"data": {
"voltage_full": "Voltage (batterijen vol)",
"voltage_low": "Voltage (batteries leeg)"
},
"description": "Batterij opties",
"title": "SureHA opties"
}
}
}
}
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "SureHA",
"documentation": "https://github.com/benleb/sureha",
"content_in_root": true,
"content_in_root": false,
"render_readme": true,
"domains": [
"binary_sensor",
Expand Down

0 comments on commit 96ab27a

Please sign in to comment.