mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Update surepy to v0.4.0 (#44556)
* Update surepy to v0.4.0 * Clarify pylint disable Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
321c0a87ae
commit
a6e474c7c9
@ -3,10 +3,11 @@ import logging
|
||||
from typing import Any, Dict, List
|
||||
|
||||
from surepy import (
|
||||
MESTART_RESOURCE,
|
||||
SurePetcare,
|
||||
SurePetcareAuthenticationError,
|
||||
SurePetcareError,
|
||||
SureProductID,
|
||||
SurepyProduct,
|
||||
)
|
||||
import voluptuous as vol
|
||||
|
||||
@ -81,7 +82,7 @@ async def async_setup(hass, config) -> bool:
|
||||
async_get_clientsession(hass),
|
||||
api_timeout=SURE_API_TIMEOUT,
|
||||
)
|
||||
await surepy.get_data()
|
||||
|
||||
except SurePetcareAuthenticationError:
|
||||
_LOGGER.error("Unable to connect to surepetcare.io: Wrong credentials!")
|
||||
return False
|
||||
@ -91,14 +92,14 @@ async def async_setup(hass, config) -> bool:
|
||||
|
||||
# add feeders
|
||||
things = [
|
||||
{CONF_ID: feeder, CONF_TYPE: SureProductID.FEEDER}
|
||||
{CONF_ID: feeder, CONF_TYPE: SurepyProduct.FEEDER}
|
||||
for feeder in conf[CONF_FEEDERS]
|
||||
]
|
||||
|
||||
# add flaps (don't differentiate between CAT and PET for now)
|
||||
things.extend(
|
||||
[
|
||||
{CONF_ID: flap, CONF_TYPE: SureProductID.PET_FLAP}
|
||||
{CONF_ID: flap, CONF_TYPE: SurepyProduct.PET_FLAP}
|
||||
for flap in conf[CONF_FLAPS]
|
||||
]
|
||||
)
|
||||
@ -109,20 +110,20 @@ async def async_setup(hass, config) -> bool:
|
||||
device_data = await surepy.device(device[CONF_ID])
|
||||
if (
|
||||
CONF_PARENT in device_data
|
||||
and device_data[CONF_PARENT][CONF_PRODUCT_ID] == SureProductID.HUB
|
||||
and device_data[CONF_PARENT][CONF_PRODUCT_ID] == SurepyProduct.HUB
|
||||
and device_data[CONF_PARENT][CONF_ID] not in hub_ids
|
||||
):
|
||||
things.append(
|
||||
{
|
||||
CONF_ID: device_data[CONF_PARENT][CONF_ID],
|
||||
CONF_TYPE: SureProductID.HUB,
|
||||
CONF_TYPE: SurepyProduct.HUB,
|
||||
}
|
||||
)
|
||||
hub_ids.add(device_data[CONF_PARENT][CONF_ID])
|
||||
|
||||
# add pets
|
||||
things.extend(
|
||||
[{CONF_ID: pet, CONF_TYPE: SureProductID.PET} for pet in conf[CONF_PETS]]
|
||||
[{CONF_ID: pet, CONF_TYPE: SurepyProduct.PET} for pet in conf[CONF_PETS]]
|
||||
)
|
||||
|
||||
_LOGGER.debug("Devices and Pets to setup: %s", things)
|
||||
@ -158,8 +159,11 @@ class SurePetcareAPI:
|
||||
async def async_update(self, arg: Any = None) -> None:
|
||||
"""Refresh Sure Petcare data."""
|
||||
|
||||
await self.surepy.get_data()
|
||||
|
||||
# Fetch all data from SurePet API, refreshing the surepy cache
|
||||
# TODO: get surepy upstream to add a method to clear the cache explicitly pylint: disable=fixme
|
||||
await self.surepy._get_resource( # pylint: disable=protected-access
|
||||
resource=MESTART_RESOURCE
|
||||
)
|
||||
for thing in self.ids:
|
||||
sure_id = thing[CONF_ID]
|
||||
sure_type = thing[CONF_TYPE]
|
||||
@ -168,13 +172,13 @@ class SurePetcareAPI:
|
||||
type_state = self.states.setdefault(sure_type, {})
|
||||
|
||||
if sure_type in [
|
||||
SureProductID.CAT_FLAP,
|
||||
SureProductID.PET_FLAP,
|
||||
SureProductID.FEEDER,
|
||||
SureProductID.HUB,
|
||||
SurepyProduct.CAT_FLAP,
|
||||
SurepyProduct.PET_FLAP,
|
||||
SurepyProduct.FEEDER,
|
||||
SurepyProduct.HUB,
|
||||
]:
|
||||
type_state[sure_id] = await self.surepy.device(sure_id)
|
||||
elif sure_type == SureProductID.PET:
|
||||
elif sure_type == SurepyProduct.PET:
|
||||
type_state[sure_id] = await self.surepy.pet(sure_id)
|
||||
|
||||
except SurePetcareError as error:
|
||||
|
@ -3,7 +3,7 @@ from datetime import datetime
|
||||
import logging
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
from surepy import SureLocationID, SureProductID
|
||||
from surepy import SureLocationID, SurepyProduct
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
DEVICE_CLASS_CONNECTIVITY,
|
||||
@ -37,15 +37,15 @@ async def async_setup_platform(
|
||||
|
||||
# connectivity
|
||||
if sure_type in [
|
||||
SureProductID.CAT_FLAP,
|
||||
SureProductID.PET_FLAP,
|
||||
SureProductID.FEEDER,
|
||||
SurepyProduct.CAT_FLAP,
|
||||
SurepyProduct.PET_FLAP,
|
||||
SurepyProduct.FEEDER,
|
||||
]:
|
||||
entities.append(DeviceConnectivity(sure_id, sure_type, spc))
|
||||
|
||||
if sure_type == SureProductID.PET:
|
||||
if sure_type == SurepyProduct.PET:
|
||||
entity = Pet(sure_id, spc)
|
||||
elif sure_type == SureProductID.HUB:
|
||||
elif sure_type == SurepyProduct.HUB:
|
||||
entity = Hub(sure_id, spc)
|
||||
else:
|
||||
continue
|
||||
@ -63,7 +63,7 @@ class SurePetcareBinarySensor(BinarySensorEntity):
|
||||
_id: int,
|
||||
spc: SurePetcareAPI,
|
||||
device_class: str,
|
||||
sure_type: SureProductID,
|
||||
sure_type: SurepyProduct,
|
||||
):
|
||||
"""Initialize a Sure Petcare binary sensor."""
|
||||
self._id = _id
|
||||
@ -138,7 +138,7 @@ class Hub(SurePetcareBinarySensor):
|
||||
|
||||
def __init__(self, _id: int, spc: SurePetcareAPI) -> None:
|
||||
"""Initialize a Sure Petcare Hub."""
|
||||
super().__init__(_id, spc, DEVICE_CLASS_CONNECTIVITY, SureProductID.HUB)
|
||||
super().__init__(_id, spc, DEVICE_CLASS_CONNECTIVITY, SurepyProduct.HUB)
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
@ -168,7 +168,7 @@ class Pet(SurePetcareBinarySensor):
|
||||
|
||||
def __init__(self, _id: int, spc: SurePetcareAPI) -> None:
|
||||
"""Initialize a Sure Petcare Pet."""
|
||||
super().__init__(_id, spc, DEVICE_CLASS_PRESENCE, SureProductID.PET)
|
||||
super().__init__(_id, spc, DEVICE_CLASS_PRESENCE, SurepyProduct.PET)
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
@ -205,7 +205,7 @@ class DeviceConnectivity(SurePetcareBinarySensor):
|
||||
def __init__(
|
||||
self,
|
||||
_id: int,
|
||||
sure_type: SureProductID,
|
||||
sure_type: SurepyProduct,
|
||||
spc: SurePetcareAPI,
|
||||
) -> None:
|
||||
"""Initialize a Sure Petcare Device."""
|
||||
|
@ -3,5 +3,5 @@
|
||||
"name": "Sure Petcare",
|
||||
"documentation": "https://www.home-assistant.io/integrations/surepetcare",
|
||||
"codeowners": ["@benleb"],
|
||||
"requirements": ["surepy==0.2.6"]
|
||||
"requirements": ["surepy==0.4.0"]
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
import logging
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
from surepy import SureLockStateID, SureProductID
|
||||
from surepy import SureLockStateID, SurepyProduct
|
||||
|
||||
from homeassistant.const import (
|
||||
ATTR_VOLTAGE,
|
||||
@ -40,13 +40,13 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||
sure_type = entity[CONF_TYPE]
|
||||
|
||||
if sure_type in [
|
||||
SureProductID.CAT_FLAP,
|
||||
SureProductID.PET_FLAP,
|
||||
SureProductID.FEEDER,
|
||||
SurepyProduct.CAT_FLAP,
|
||||
SurepyProduct.PET_FLAP,
|
||||
SurepyProduct.FEEDER,
|
||||
]:
|
||||
entities.append(SureBattery(entity[CONF_ID], sure_type, spc))
|
||||
|
||||
if sure_type in [SureProductID.CAT_FLAP, SureProductID.PET_FLAP]:
|
||||
if sure_type in [SurepyProduct.CAT_FLAP, SurepyProduct.PET_FLAP]:
|
||||
entities.append(Flap(entity[CONF_ID], sure_type, spc))
|
||||
|
||||
async_add_entities(entities, True)
|
||||
@ -55,7 +55,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||
class SurePetcareSensor(Entity):
|
||||
"""A binary sensor implementation for Sure Petcare Entities."""
|
||||
|
||||
def __init__(self, _id: int, sure_type: SureProductID, spc: SurePetcareAPI):
|
||||
def __init__(self, _id: int, sure_type: SurepyProduct, spc: SurePetcareAPI):
|
||||
"""Initialize a Sure Petcare sensor."""
|
||||
|
||||
self._id = _id
|
||||
|
@ -2127,7 +2127,7 @@ sucks==0.9.4
|
||||
sunwatcher==0.2.1
|
||||
|
||||
# homeassistant.components.surepetcare
|
||||
surepy==0.2.6
|
||||
surepy==0.4.0
|
||||
|
||||
# homeassistant.components.swiss_hydrological_data
|
||||
swisshydrodata==0.0.3
|
||||
|
@ -1049,7 +1049,7 @@ stringcase==1.2.0
|
||||
sunwatcher==0.2.1
|
||||
|
||||
# homeassistant.components.surepetcare
|
||||
surepy==0.2.6
|
||||
surepy==0.4.0
|
||||
|
||||
# homeassistant.components.synology_dsm
|
||||
synologydsm-api==1.0.1
|
||||
|
@ -18,6 +18,5 @@ async def surepetcare(hass):
|
||||
async_get_clientsession(hass),
|
||||
api_timeout=1,
|
||||
)
|
||||
instance.get_data = AsyncMock(return_value=None)
|
||||
|
||||
instance._get_resource = AsyncMock(return_value=None)
|
||||
yield mock_surepetcare
|
||||
|
@ -1,4 +1,6 @@
|
||||
"""The tests for the Sure Petcare binary sensor platform."""
|
||||
from surepy import MESTART_RESOURCE
|
||||
|
||||
from homeassistant.components.surepetcare.const import DOMAIN
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
@ -16,8 +18,7 @@ EXPECTED_ENTITY_IDS = {
|
||||
async def test_binary_sensors(hass, surepetcare) -> None:
|
||||
"""Test the generation of unique ids."""
|
||||
instance = surepetcare.return_value
|
||||
instance.data = MOCK_API_DATA
|
||||
instance.get_data.return_value = MOCK_API_DATA
|
||||
instance._resource[MESTART_RESOURCE] = {"data": MOCK_API_DATA}
|
||||
|
||||
with _patch_sensor_setup():
|
||||
assert await async_setup_component(hass, DOMAIN, MOCK_CONFIG)
|
||||
|
Loading…
x
Reference in New Issue
Block a user