Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix deprications and add unit of measurement to battery_level sensor #53

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
0ab095c
Update sensor.py
ChristophCaina Dec 28, 2023
8aba915
Update manifest.json
ChristophCaina Dec 28, 2023
507c2da
Update binary_sensor.py
ChristophCaina Dec 28, 2023
2697441
rebase from running HA
ChristophCaina Dec 28, 2023
0802039
Update binary_sensor.py
ChristophCaina Dec 28, 2023
3ed5a9c
Update binary_sensor.py
ChristophCaina Dec 28, 2023
f6bacf0
Update sensor.py
ChristophCaina Dec 31, 2023
c143558
Create de.json
ChristophCaina Dec 31, 2023
cc5cfe3
Update README.md
ChristophCaina Jan 1, 2024
12d6536
Delete README.md
ChristophCaina Jul 8, 2024
add09ed
Update __init__.py
ChristophCaina Jul 8, 2024
956190b
Update manifest.json
ChristophCaina Jul 8, 2024
b66d288
Merge pull request #16 from ChristophCaina/fix-deprication-warnings-f…
ChristophCaina Jul 8, 2024
6428bd9
Delete manifest.json
ChristophCaina Jul 8, 2024
d735d65
Create manifest.json
ChristophCaina Jul 10, 2024
03c5de9
Update manifest.json
ChristophCaina Jul 10, 2024
c718b59
Update manifest.json
ChristophCaina Jul 10, 2024
b81c707
Create README.md
ChristophCaina Jul 10, 2024
a53c7de
Update manifest.json
ChristophCaina Jul 11, 2024
9aa7348
Update README.md
ChristophCaina Jul 11, 2024
c539bba
Update hacs.json
ChristophCaina Jul 11, 2024
b5a6f25
restructured content
ChristophCaina Jul 11, 2024
0fbd68c
Delete __init__.py
ChristophCaina Jul 11, 2024
2506773
Delete binary_sensor.py
ChristophCaina Jul 11, 2024
3e51a9f
Delete custom_components/manifest.json
ChristophCaina Jul 11, 2024
efd9691
Add files via upload
ChristophCaina Jul 11, 2024
06ad0df
Delete config_flow.py
ChristophCaina Jul 11, 2024
630ed5d
Delete const.py
ChristophCaina Jul 11, 2024
82a8862
Delete device_tracker.py
ChristophCaina Jul 11, 2024
a10b37a
Delete manifest.json
ChristophCaina Jul 11, 2024
27d9874
Delete sensor.py
ChristophCaina Jul 11, 2024
47226bf
Delete services.yaml
ChristophCaina Jul 11, 2024
9ae2601
Delete strings.json
ChristophCaina Jul 11, 2024
752d0e4
Update manifest.json
ChristophCaina Jul 11, 2024
8beb48c
Update manifest.json
ChristophCaina Jul 12, 2024
a9b8666
Update hacs.json
ChristophCaina Jul 12, 2024
058f7c2
Update manifest.json
ChristophCaina Jul 12, 2024
de1f9af
Create nl.json
ChristophCaina Jul 19, 2024
13342dd
Delete README.md
ChristophCaina Jul 19, 2024
4ea6065
Delete custom_components/sureha/manifest.json
ChristophCaina Jul 19, 2024
db37934
Delete hacs.json
ChristophCaina Jul 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
226 changes: 0 additions & 226 deletions README.md

This file was deleted.

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.
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.
Loading