Skip to content

Commit

Permalink
Merge pull request #11 from RobertD502/dev
Browse files Browse the repository at this point in the history
add support for pura max, handle server busy error, add translation support
  • Loading branch information
RobertD502 authored Jun 2, 2023
2 parents 828d853 + 988c381 commit 892666d
Show file tree
Hide file tree
Showing 17 changed files with 4,828 additions and 809 deletions.
281 changes: 275 additions & 6 deletions README.md

Large diffs are not rendered by default.

169 changes: 102 additions & 67 deletions custom_components/petkit/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,46 @@ async def async_setup_entry(

for wf_id, wf_data in coordinator.data.water_fountains.items():
# Water Fountains (W5)
binary_sensors.extend((
WFWater(coordinator, wf_id),
))
binary_sensors.append(
WFWater(coordinator, wf_id)
)

for feeder_id, feeder_data in coordinator.data.feeders.items():
# All Feeders
binary_sensors.extend((
FoodLevel(coordinator, feeder_id),
))
binary_sensors.append(
FoodLevel(coordinator, feeder_id)
)

# D4 Feeder
if feeder_data.type == 'd4':
binary_sensors.extend((
BatteryInstalled(coordinator, feeder_id),
))
binary_sensors.append(
BatteryInstalled(coordinator, feeder_id)
)

# D3 Feeder
if feeder_data.type == 'd3':
binary_sensors.extend((
BatteryCharging(coordinator, feeder_id),
))
binary_sensors.append(
BatteryCharging(coordinator, feeder_id)
)

# Litter boxes
for lb_id, lb_data in coordinator.data.litter_boxes.items():
# Pura X & Pura MAX
if lb_data.type in ['t3', 't4']:
binary_sensors.extend((
LBBinFull(coordinator, lb_id),
LBLitterLack(coordinator, lb_id),
))
# Pura X & Pura MAX with Pura Air
if (lb_data.type == 't3') or ('k3Device' in lb_data.device_detail):
binary_sensors.append(
LBDeodorizerLack(coordinator, lb_id)
)
# Pura X
binary_sensors.extend((
LBBinFull(coordinator, lb_id),
LBLitterLack(coordinator, lb_id),
LBDeodorizerLack(coordinator, lb_id),
LBManuallyPaused(coordinator, lb_id),
))
if lb_data.type == 't3':
binary_sensors.append(
LBManuallyPaused(coordinator, lb_id)
)

async_add_entities(binary_sensors)

Expand Down Expand Up @@ -93,18 +102,18 @@ def unique_id(self) -> str:

return str(self.wf_data.id) + '_water_level'

@property
def name(self) -> str:
"""Return name of the entity."""

return "Water level"

@property
def has_entity_name(self) -> bool:
"""Indicate that entity has name defined."""

return True

@property
def translation_key(self) -> str:
"""Translation key for this entity."""

return "water_level"

@property
def device_class(self) -> BinarySensorDeviceClass:
"""Return entity device class."""
Expand Down Expand Up @@ -160,18 +169,18 @@ def unique_id(self) -> str:

return str(self.feeder_data.id) + '_food_level'

@property
def name(self) -> str:
"""Return name of the entity."""

return "Food level"

@property
def has_entity_name(self) -> bool:
"""Indicate that entity has name defined."""

return True

@property
def translation_key(self) -> str:
"""Translation key for this entity."""

return "food_level"

@property
def device_class(self) -> BinarySensorDeviceClass:
"""Return entity device class."""
Expand Down Expand Up @@ -241,18 +250,18 @@ def unique_id(self) -> str:

return str(self.feeder_data.id) + '_battery_installed'

@property
def name(self) -> str:
"""Return name of the entity."""

return "Battery installed"

@property
def has_entity_name(self) -> bool:
"""Indicate that entity has name defined."""

return True

@property
def translation_key(self) -> str:
"""Translation key for this entity."""

return "battery_installed"

@property
def entity_category(self) -> EntityCategory:
"""Set category to diagnostic."""
Expand Down Expand Up @@ -306,18 +315,18 @@ def unique_id(self) -> str:

return str(self.feeder_data.id) + '_battery_charging'

@property
def name(self) -> str:
"""Return name of the entity."""

return "Battery"

@property
def has_entity_name(self) -> bool:
"""Indicate that entity has name defined."""

return True

@property
def translation_key(self) -> str:
"""Translation key for this entity."""

return "battery"

@property
def entity_category(self) -> EntityCategory:
"""Set category to diagnostic."""
Expand Down Expand Up @@ -377,18 +386,18 @@ def unique_id(self) -> str:

return str(self.lb_data.id) + '_wastebin'

@property
def name(self) -> str:
"""Return name of the entity."""

return "Wastebin"

@property
def has_entity_name(self) -> bool:
"""Indicate that entity has name defined."""

return True

@property
def translation_key(self) -> str:
"""Translation key for this entity."""

return "wastebin"

@property
def icon(self) -> str:
"""Set icon."""
Expand Down Expand Up @@ -439,18 +448,18 @@ def unique_id(self) -> str:

return str(self.lb_data.id) + '_litter_lack'

@property
def name(self) -> str:
"""Return name of the entity."""

return "Litter"

@property
def has_entity_name(self) -> bool:
"""Indicate that entity has name defined."""

return True

@property
def translation_key(self) -> str:
"""Translation key for this entity."""

return "litter"

@property
def icon(self) -> str:
"""Set icon."""
Expand Down Expand Up @@ -501,23 +510,33 @@ def unique_id(self) -> str:

return str(self.lb_data.id) + '_deodorizer_lack'

@property
def name(self) -> str:
"""Return name of the entity."""

return "Deodorizer"

@property
def has_entity_name(self) -> bool:
"""Indicate that entity has name defined."""

return True

@property
def translation_key(self) -> str:
"""Translation key for this entity."""

#Pura Air
if 'k3Device' in self.lb_data.device_detail:
return "pura_air_liquid"
#Pura X
else:
return "deodorizer"

@property
def icon(self) -> str:
"""Set icon."""

return 'mdi:spray'
#Pura Air
if 'k3Device' in self.lb_data.device_detail:
return 'mdi:cup'
#Pura X
else:
return 'mdi:spray'

@property
def device_class(self) -> BinarySensorDeviceClass:
Expand All @@ -531,6 +550,22 @@ def is_on(self) -> bool:

return self.lb_data.device_detail['state']['liquidLack']

@property
def available(self) -> bool:
"""Determine if entity is available.
Return true if there is a Pura Air
device associated or this is a Pura X.
"""

if self.lb_data.type == 't4':
if 'k3Device' in self.lb_data.device_detail:
return True
else:
return False
else:
return True


class LBManuallyPaused(CoordinatorEntity, BinarySensorEntity):
"""Representation of if litter box is manually paused by user."""
Expand Down Expand Up @@ -563,18 +598,18 @@ def unique_id(self) -> str:

return str(self.lb_data.id) + '_manually_paused'

@property
def name(self) -> str:
"""Return name of the entity."""

return "Manually paused"

@property
def has_entity_name(self) -> bool:
"""Indicate that entity has name defined."""

return True

@property
def translation_key(self) -> str:
"""Translation key for this entity."""

return "manually_paused"

@property
def icon(self) -> str:
"""Set icon."""
Expand Down
Loading

0 comments on commit 892666d

Please sign in to comment.