Conversation
* custom_components/daikin_onecta/const.py:
* custom_components/daikin_onecta/sensor.py:
* custom_components/daikin_onecta/const.py:
* custom_components/daikin_onecta/sensor.py:
* custom_components/daikin_onecta/translations/en.json:
* custom_components/daikin_onecta/translations/nl.json:
* tests/snapshots/test_init.ambr:
|
Warning Rate limit exceeded@jwillemsen has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 12 minutes and 47 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (2)
WalkthroughAdds a new "monthly" energy period and four monthly energy sensor entries, updates sensor value extraction to index into period arrays (weekly/monthly/other variants), and adds English and Dutch translations for the new sensors. The new monthly period constant value is misspelled as "montlhly". Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #568 +/- ##
==========================================
+ Coverage 96.68% 96.72% +0.03%
==========================================
Files 16 16
Lines 1719 1738 +19
==========================================
+ Hits 1662 1681 +19
Misses 57 57 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
custom_components/daikin_onecta/sensor.py (2)
40-77: Clarify yearly→monthly sensor creation pathThe extra block for
period == SENSOR_PERIOD_YEARLYcreates a second sensor withperiodrewritten toSENSOR_PERIOD_MONTHLYwhile still relying on the same underlying period data ("m"viaSENSOR_PERIODS_ARRAY). Functionally this gives you both yearly and monthly sensors from the same source, which seems intended, but the reuse/mutation ofperiodis a bit opaque.Consider assigning to a separate local (e.g.
monthly_period = SENSOR_PERIOD_MONTHLY) instead of mutatingperiod, and perhaps add a brief comment that the backend only exposes"m"and you fan out to both yearly and monthly sensors in HA.Please confirm this behavior matches the Daikin API semantics (single
"m"bucket providing both yearly aggregate and per‑month values) to avoid surprising duplication.
220-247: Verify monthly index math and guard against unexpected array layoutsThe new logic
- reuses
SENSOR_PERIODS_ARRAY[self._period]so both yearly and monthly sensors read from the"m"array, and- for monthly uses
start_index = 11 + date.today().month/end_index = start_index + 1.This assumes:
- the
"m"array exists for all created sensors, and- it has at least
11 + monthentries (so indices 12–23 for months 1–12), otherwiseenergy_values[start_index:end_index]will be empty and monthly consumption will silently be0.If that layout is guaranteed by the API, this is fine; if not, consider:
- Adding a simple bounds check before slicing (logging and leaving
energy_valueasNoneif the slice would be empty), and/or- Documenting the assumed array structure (e.g. “positions 12–23 are months 1–12”).
Also, if the backend month indexing is 0‑based rather than 1‑based, this could be off by one; worth confirming against real payloads.
Please validate the
"m"array shape and month index mapping with a couple of live responses (e.g. printlen(energy_values)and sample contents) to ensure the current‑month element is correctly addressed.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
custom_components/daikin_onecta/const.py(5 hunks)custom_components/daikin_onecta/sensor.py(4 hunks)custom_components/daikin_onecta/translations/en.json(4 hunks)custom_components/daikin_onecta/translations/nl.json(4 hunks)
🔇 Additional comments (5)
custom_components/daikin_onecta/sensor.py (1)
3-3: New imports for date and period constants look consistent
dateand the new period-related imports are all used insensor_valueandhandle_energy_sensors; no issues spotted.Also applies to: 18-23
custom_components/daikin_onecta/const.py (2)
29-44: Monthly period constant and array mapping are internally consistentDefining
SENSOR_PERIOD_MONTHLY = "mo"and mapping both yearly and monthly to"m"inSENSOR_PERIODS_ARRAYcleanly separates HA’s notion of periods from the backend’s"m"bucket while keeping lookups simple. No issues from a constants/layout perspective.Please double‑check against the Daikin API docs/sample payloads that
"m"is indeed the correct key for both yearly aggregate and per‑month arrays to avoid surprises if the API ever introduces a distinct key.
491-499: New monthly energy VALUE_SENSOR_MAPPING entries align with existing onesThe four new mappings:
CoolingMonthlyElectricalConsumptionHeatingMonthlyElectricalConsumptionCoolingMonthlyGasConsumptionHeatingMonthlyGasConsumptionall match the existing daily/weekly/yearly counterparts in terms of device class (
ENERGY), state class (TOTAL_INCREASING), unit (kWh), icons, and enabled state, and their translation keys line up with the new translation entries.Looks good and should integrate cleanly with the new monthly period handling in
sensor.py.Also applies to: 527-535, 563-571, 599-607
custom_components/daikin_onecta/translations/en.json (1)
67-69: Monthly electrical/gas sensor translations match const mappingsThe three new entries:
coolingmonthlyelectricalconsumptionheatingmonthlyelectricalconsumptioncoolingmonthlygasconsumptionall use clear English names and align with the corresponding
TRANSLATION_KEYvalues inVALUE_SENSOR_MAPPING. No issues.Also applies to: 79-81, 91-93
custom_components/daikin_onecta/translations/nl.json (1)
66-68: Dutch monthly energy sensor translations are consistent and alignedThe four new NL entries for monthly electrical/gas consumption match the
TRANSLATION_KEYvalues inVALUE_SENSOR_MAPPINGand are phrased consistently with the existing daily/weekly/yearly variants.No issues from a localization perspective.
Also applies to: 78-80, 90-92, 102-104
| "heatingweeklymonthlyconsumption": { | ||
| "name": "Heating monthly gas consumption" | ||
| }, |
There was a problem hiding this comment.
Fix translation key typo for heating monthly gas consumption
VALUE_SENSOR_MAPPING defines the translation key "heatingmonthlygasconsumption", but the EN translation uses "heatingweeklymonthlyconsumption". As a result, the monthly heating gas sensor will not pick up this name, and you’ll have a dead translation entry.
Recommend renaming the key to match const.py:
- "heatingweeklymonthlyconsumption": {
+ "heatingmonthlygasconsumption": {
"name": "Heating monthly gas consumption"
},📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| "heatingweeklymonthlyconsumption": { | |
| "name": "Heating monthly gas consumption" | |
| }, | |
| "heatingmonthlygasconsumption": { | |
| "name": "Heating monthly gas consumption" | |
| }, |
🤖 Prompt for AI Agents
In custom_components/daikin_onecta/translations/en.json around lines 103-105,
the translation key "heatingweeklymonthlyconsumption" is wrong; update the JSON
key to "heatingmonthlygasconsumption" to match VALUE_SENSOR_MAPPING in const.py
so the monthly heating gas sensor picks up the name, and remove the old unused
key if present.
* custom_components/daikin_onecta/const.py:
* custom_components/daikin_onecta/sensor.py:
* custom_components/daikin_onecta/translations/en.json:
* tests/snapshots/test_init.ambr:
…kin_onecta into jwi-monthlysensor
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
custom_components/daikin_onecta/sensor.py (1)
51-64: Consider improving variable naming consistency.The variable name
periodi(line 53) and its usage in the log message (line 55) appear inconsistent with the rest of the codebase. Consider renaming toperiod_monthlyormonthly_periodfor better clarity.Apply this diff to improve naming:
periodName = SENSOR_PERIODS.get(period) # When we have the yearly sensor we also add a monthly if period == SENSOR_PERIOD_YEARLY: - periodi = SENSOR_PERIOD_MONTHLY + period_monthly = SENSOR_PERIOD_MONTHLY _LOGGER.info( - "Device '%s:%s' provides mode %s %s supports periodi %s", + "Device '%s:%s' provides mode %s %s supports monthly period %s", device.name, embedded_id, management_point_type, mode, - periodi, + period_monthly, ) sensor = f"{device.name} {sensor_type} {management_point_type} {mode} {SENSOR_PERIOD_MONTHLY}" _LOGGER.info("Proposing sensor '%s'", sensor) - sensors.append(DaikinEnergySensor(device, coordinator, embedded_id, management_point_type, sensor_type, mode, periodi)) + sensors.append(DaikinEnergySensor(device, coordinator, embedded_id, management_point_type, sensor_type, mode, period_monthly))
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
custom_components/daikin_onecta/const.py(5 hunks)custom_components/daikin_onecta/sensor.py(4 hunks)custom_components/daikin_onecta/translations/en.json(4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- custom_components/daikin_onecta/translations/en.json
🧰 Additional context used
🧬 Code graph analysis (1)
custom_components/daikin_onecta/sensor.py (2)
custom_components/daikin_onecta/climate.py (1)
name(235-239)tests/test_coordinator.py (1)
coordinator(33-47)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Run tests (3.13)
🔇 Additional comments (2)
custom_components/daikin_onecta/const.py (1)
491-499: LGTM!The four new monthly sensor mappings (CoolingMonthlyElectricalConsumption, HeatingMonthlyElectricalConsumption, CoolingMonthlyGasConsumption, HeatingMonthlyGasConsumption) are correctly configured and consistent with the existing Daily/Weekly/Yearly sensor patterns.
Also applies to: 527-535, 563-571, 599-607
custom_components/daikin_onecta/sensor.py (1)
3-3: LGTM!The new imports (
date,SENSOR_PERIOD_MONTHLY,SENSOR_PERIOD_YEARLY,SENSOR_PERIODS_ARRAY) are appropriate for the monthly sensor functionality being added.Also applies to: 18-18, 20-20, 22-22
* custom_components/daikin_onecta/const.py:
* tests/snapshots/test_init.ambr:
* custom_components/daikin_onecta/sensor.py:
Summary by CodeRabbit
New Features
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.