Clean up Surpetcare (#53699)
This commit is contained in:
parent
007ecc51e5
commit
204426009f
1 changed files with 9 additions and 20 deletions
|
@ -24,7 +24,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||
async def async_setup_platform(
|
||||
hass, config, async_add_entities, discovery_info=None
|
||||
) -> None:
|
||||
"""Set up Sure PetCare Flaps sensors based on a config entry."""
|
||||
"""Set up Sure PetCare Flaps binary sensors based on a config entry."""
|
||||
if discovery_info is None:
|
||||
return
|
||||
|
||||
|
@ -42,8 +42,7 @@ async def async_setup_platform(
|
|||
EntityType.FELAQUA,
|
||||
]:
|
||||
entities.append(DeviceConnectivity(surepy_entity.id, spc))
|
||||
|
||||
if surepy_entity.type == EntityType.PET:
|
||||
elif surepy_entity.type == EntityType.PET:
|
||||
entities.append(Pet(surepy_entity.id, spc))
|
||||
elif surepy_entity.type == EntityType.HUB:
|
||||
entities.append(Hub(surepy_entity.id, spc))
|
||||
|
@ -75,16 +74,10 @@ class SurePetcareBinarySensor(BinarySensorEntity):
|
|||
else:
|
||||
name = f"Unnamed {surepy_entity.type.name.capitalize()}"
|
||||
|
||||
self._name = f"{surepy_entity.type.name.capitalize()} {name.capitalize()}"
|
||||
|
||||
self._attr_device_class = device_class
|
||||
self._attr_name = f"{surepy_entity.type.name.capitalize()} {name.capitalize()}"
|
||||
self._attr_unique_id = f"{surepy_entity.household_id}-{self._id}"
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the device if any."""
|
||||
return self._name
|
||||
|
||||
@abstractmethod
|
||||
@callback
|
||||
def _async_update(self) -> None:
|
||||
|
@ -99,7 +92,7 @@ class SurePetcareBinarySensor(BinarySensorEntity):
|
|||
|
||||
|
||||
class Hub(SurePetcareBinarySensor):
|
||||
"""Sure Petcare Pet."""
|
||||
"""Sure Petcare Hub."""
|
||||
|
||||
def __init__(self, _id: int, spc: SurePetcareAPI) -> None:
|
||||
"""Initialize a Sure Petcare Hub."""
|
||||
|
@ -120,7 +113,7 @@ class Hub(SurePetcareBinarySensor):
|
|||
}
|
||||
else:
|
||||
self._attr_extra_state_attributes = None
|
||||
_LOGGER.debug("%s -> state: %s", self._name, state)
|
||||
_LOGGER.debug("%s -> state: %s", self.name, state)
|
||||
self.async_write_ha_state()
|
||||
|
||||
|
||||
|
@ -147,12 +140,12 @@ class Pet(SurePetcareBinarySensor):
|
|||
}
|
||||
else:
|
||||
self._attr_extra_state_attributes = None
|
||||
_LOGGER.debug("%s -> state: %s", self._name, state)
|
||||
_LOGGER.debug("%s -> state: %s", self.name, state)
|
||||
self.async_write_ha_state()
|
||||
|
||||
|
||||
class DeviceConnectivity(SurePetcareBinarySensor):
|
||||
"""Sure Petcare Pet."""
|
||||
"""Sure Petcare Device."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -161,15 +154,11 @@ class DeviceConnectivity(SurePetcareBinarySensor):
|
|||
) -> None:
|
||||
"""Initialize a Sure Petcare Device."""
|
||||
super().__init__(_id, spc, DEVICE_CLASS_CONNECTIVITY)
|
||||
self._attr_name = f"{self.name}_connectivity"
|
||||
self._attr_unique_id = (
|
||||
f"{self._spc.states[self._id].household_id}-{self._id}-connectivity"
|
||||
)
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the device if any."""
|
||||
return f"{self._name}_connectivity"
|
||||
|
||||
@callback
|
||||
def _async_update(self) -> None:
|
||||
"""Get the latest data and update the state."""
|
||||
|
@ -183,5 +172,5 @@ class DeviceConnectivity(SurePetcareBinarySensor):
|
|||
}
|
||||
else:
|
||||
self._attr_extra_state_attributes = None
|
||||
_LOGGER.debug("%s -> state: %s", self._name, state)
|
||||
_LOGGER.debug("%s -> state: %s", self.name, state)
|
||||
self.async_write_ha_state()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue