Skip to content

Commit 32bce46

Browse files
Fix/Removed doubled shared-pets API calls (#213)
* Fixed pet age & removed pet eating amounts * Fixed age entity * Removed doubled shared-pets API calls * Added missing default value when checking integration option --------- Co-authored-by: Jamie Jones <29973406+jjjonesjr33@users.noreply.github.com>
1 parent 6722e3f commit 32bce46

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

  • custom_components/petlibro

custom_components/petlibro/hub.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,11 @@ async def load_devices(self) -> None:
9999

100100
# Get pet ids bound to this device if it's shared and shared pets are enabled
101101
if (
102-
self.entry.options.get(IntegrationSetting.ENABLE_SHARED_PETS)
103-
and device_data.get("shareId")
102+
self.entry.options.get(
103+
IntegrationSetting.ENABLE_SHARED_PETS,
104+
IntegrationSetting.ENABLE_SHARED_PETS.default,
105+
)
106+
and device_data.get("shareId")
104107
and device_sn != "unknown"
105108
):
106109
bound_pets = await self.api.device_get_bound_pets(device_sn)
@@ -166,18 +169,10 @@ async def load_pets(self) -> None:
166169
try:
167170
response = await self.api.pets.get_list()
168171
pet_list: list[dict] = response.get("petList", [])
169-
170-
#TODO seperate shared pets into a different try so owned ones can still get loaded
171-
if self.entry.options.get(IntegrationSetting.ENABLE_SHARED_PETS):
172-
for pet_data in pet_list:
173-
self.pets_helper.shared_pet_ids.discard(pet_data.get("id"))
174-
175-
for pet_id in self.pets_helper.shared_pet_ids:
176-
pet_list.append(await self.api.pets.get_details(pet_id))
177-
178-
_LOGGER.debug(f"Fetched {len(pet_list)} pets from the API.")
172+
pet_count = len(pet_list)
173+
_LOGGER.debug(f"Fetched {pet_count} owned pets from the API.")
179174
except Exception:
180-
_LOGGER.exception("Error fetching pet info.")
175+
_LOGGER.exception("Error fetching owned pet info.")
181176
return
182177

183178
# Get shared pets if set to do so.
@@ -189,6 +184,7 @@ async def load_pets(self) -> None:
189184
for pet_id in self.pets_helper.shared_pet_ids:
190185
if pet_data := await self.api.pets.get_details(pet_id):
191186
pet_list.append(pet_data)
187+
_LOGGER.debug(f"Fetched {len(pet_list) - pet_count} shared pets from the API.")
192188
except Exception:
193189
_LOGGER.error("Error fetching shared pet info.")
194190

0 commit comments

Comments
 (0)