Feat: Added new state attributes to provide day of week information#103
Feat: Added new state attributes to provide day of week information#103olibos merged 5 commits intoolibos:mainfrom
Conversation
Interesting for auto sorting
WalkthroughThe changes modify the Changes
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
custom_components/recycle_app/opening_hours_entity.py (1)
45-46: LGTM! Consider these minor improvements.The implementation successfully adds the day of week index attribute. A few suggestions for improvement:
- The modulo operation is redundant since
DAYS_OF_WEEK.index()will always return 0-6- Consider using snake_case for the attribute name (e.g., "day_of_week")
- self._day_of_week_index = (DAYS_OF_WEEK.index(day_of_week) + 1) % 7 - self._attr_extra_state_attributes = {"day of week": self._day_of_week_index} + self._day_of_week_index = DAYS_OF_WEEK.index(day_of_week) + 1 + self._attr_extra_state_attributes = {"day_of_week": self._day_of_week_index}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
custom_components/recycle_app/opening_hours_entity.py(2 hunks)
🔇 Additional comments (1)
custom_components/recycle_app/opening_hours_entity.py (1)
67-67: Verify the day index comparison logic.The comparison looks correct but let's verify the index matching:
_day_of_week_indexis 1-based (Monday=1, ..., Sunday=7)- Need to confirm if
opening_day["day"]from the API uses the same 1-based indexing✅ Verification successful
Day index comparison is correctly implemented
The comparison is using a consistent 1-based day indexing scheme (Monday=1 through Sunday=7) on both sides:
_day_of_week_indexis properly converted to 1-based indexingopening_day["day"]from the API uses the same 1-based scheme, as verified by consistent usage in multiple components🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for any documentation or tests that might reveal the API's day indexing scheme rg -l "openingDays.*day" | xargs rg "day.*[0-9]"Length of output: 583
Script:
#!/bin/bash # Search for DAYS_OF_WEEK definition and API response handling rg "DAYS_OF_WEEK.*=" -A 3 rg -B 2 -A 5 "opening.*day.*\[.*day"Length of output: 1871
|
Hello @geertmeersman, Great addition to the integration! I’m curious about the removal of the modulo operation. With the updated code, Am I overlooking something? |
|
Seems to work correctly |
{
"openingPeriods": [
{
"openingDays": [
{
"openingHours": [
{
"_id": "676171b6328d750070a32bcd",
"from": "14:00",
"until": "20:15"
}
],
"_id": "676171b6328d750070a32bcc",
"day": 1
},
{
"openingHours": [
{
"_id": "676171b6328d750070a32bcf",
"from": "09:00",
"until": "20:15"
}
],
"_id": "676171b6328d750070a32bce",
"day": 2
},
{
"openingHours": [
{
"_id": "676171b6328d750070a32bd1",
"from": "09:00",
"until": "20:15"
}
],
"_id": "676171b6328d750070a32bd0",
"day": 3
},
{
"openingHours": [
{
"_id": "676171b6328d750070a32bd3",
"from": "09:00",
"until": "16:15"
}
],
"_id": "676171b6328d750070a32bd2",
"day": 4
},
{
"openingHours": [
{
"_id": "676171b6328d750070a32bd5",
"from": "09:00",
"until": "16:15"
}
],
"_id": "676171b6328d750070a32bd4",
"day": 5
},
{
"openingHours": [
{
"_id": "676171b6328d750070a32bd7",
"from": "09:00",
"until": "16:15"
}
],
"_id": "676171b6328d750070a32bd6",
"day": 6
},
{
"openingHours": [
{
"_id": "676171b6328d750070a32bd9",
"from": "14:00",
"until": "20:15"
}
],
"_id": "676171b6328d750070a32bd8",
"day": 0
}
],
"_id": "676171b6328d750070a32bcb",
"name": "2020",
"from": "2020-01-01T00:00:00.000Z",
"until": "2030-12-31T00:00:00.000Z"
}
],
"displayName": {
"nl": "Recypark ZUID",
"fr": "Recypark SUD",
"en": "Recypark SUD",
"de": "Recypark SUD"
},
"targets": []
}
]
} |
|
It works if the recycling parks is closed on sunday 😜 |
|
Already see the issue, had it different in my running HA instance :-) |
|
Fixed. Finally, we keep the attribute value with the US day of the week: 0 = Sunday, 6 = Saturday. For me, both the US day of the week (Sunday → Saturday) or the Belgian day of the week (Monday → Sunday) are acceptable. |
|
Changed |
|






Interesting for auto sorting
Summary by CodeRabbit