-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Hi. I wanted to try using homeassistant_petkit integration with dispenser-schedule-card, however, I found out that required sensor is not populated for my feeder
I tried to investigate a bit why that's the case and found that Feeder.device_records is not filled with the required info due to unexpected endpoint response format
Here are two responses that I got today (response value from _fetch_device_data, FeederRecord data class, FEEDER device type)
- Breakfast success, Dinner pending:
[
{
'amount': 60,
'day': 20250503,
'device_id': 0,
'items': [
{
'amount': 40,
'id': 's36000',
'name': 'Breakfast',
'petAmount': [
{
'amount': 40,
'petId': '100112726'
}
],
'src': 1,
'state': {
'completedAt': '2025-05-03T08:00:10.000+0000',
'realAmount': 40
},
'status': 0,
'time': 36000
},
{
'amount': 20,
'id': 's72000',
'name': 'Dinner',
'petAmount': [
{
'amount': 40,
'petId': '100112726'
}
],
'src': 1,
'status': 0,
'time': 72000
}
],
'realAmount': 40
}
]- Breakfast error (the feeder is empty), Dinner pending:
[
{
'amount': 60,
'day': 20250503,
'device_id': 0,
'items': [
{
'amount': 40,
'id': 's36000',
'name': 'Breakfast',
'petAmount': [
{
'amount': 40,
'petId': '100112727'
}
],
'src': 1,
'state': {
'completedAt': '2025-05-03T08:00:29.000+0000',
'errCode': 'food-0',
'errMsg': 'Food low.',
'realAmount': 0
},
'status': 0,
'time': 36000
},
{
'amount': 20,
'id': 's72000',
'name': 'Dinner',
'petAmount': [
{
'amount': 40,
'petId': '100112727'
}
],
'src': 1,
'status': 0,
'time': 72000
}
],
'realAmount': 0
}
]While the structure is similar to the expected one, there are some differences:
- There is no top-level
feedproperty, we start with an array device_idis in snake_case while camelCase is expectedpetAmountis not parsed (probably not necessary tho)errCodeinstateis string while int is expectederrMsginstateis not parsed
I tried doing some quick fixes like changing _fetch_device_data to have something like:
if device_type == FEEDER and data_class == FeederRecord:
device_data = FeederRecord(**{'feed': response})
elif isinstance(response, list):
device_data = [data_class(**item) for item in response]
elif isinstance(response, dict):
device_data = data_class(**response)But this fails for records with errors like the second one
Ideally it would be nice to separate endpoint response types from library model types, but it's not that easy to do without knowing other endpoint formats and the required library model. So I decided to just open the issue first :)