Skip to content

Consolidating shared device logic and adding new entities. - #207

Closed
dn5qMDW3 wants to merge 7 commits into
jjjonesjr33:devfrom
dn5qMDW3:dev
Closed

Consolidating shared device logic and adding new entities.#207
dn5qMDW3 wants to merge 7 commits into
jjjonesjr33:devfrom
dn5qMDW3:dev

Conversation

@dn5qMDW3

@dn5qMDW3 dn5qMDW3 commented Mar 27, 2026

Copy link
Copy Markdown

Proposed change:

This PR consolidates shared device logic into base classes, adds new entities, introduces diagnostics support, and removes unused code

DRY refactor:

  • Consolidated shared feeder properties/setters into Feeder base class and shared fountain properties into Fountain base class.
  • Extracted _cached_request() helper in api.py with 10s TTL deduplication (9 methods reduced to 2-3 lines each).
  • Device.refresh() now namespaces results (realInfo, getAttributeSetting) to eliminate redundant API calls.
  • Introduced create_platform_setup() factory to reduce boilerplate across all 8 entity platforms.

New entities:

  • Granary Smart Feeder: new sensors and binary sensors.
  • Polar Wet Food Feeder: new sensors, temperature reporting switched to Celsius.
  • Fountain devices: Water State, Remaining Water, Tank Capacity, Alert Message, Water Low, Device Fault.
  • Dockstream 2 devices: Power Source, Radar Sensing Level, Radar Gain, Radar Threshold, Human Sensitivity, Filter LED, Battery 8-Hour Supply, Volume Level.

Bug fixes:

  • Fixed available property referencing non-existent self.device in 10 device subclasses.
  • Fixed set_child_lock, set_light_enable, set_sound_enable calling .raise_for_status() on parsed JSON.
  • Fixed duplicate set_light_on/set_light_off definitions in api.py (second used wrong field names).
  • Fixed duplicate child_lock_switch in OneRFIDSmartFeeder (inverted logic removed).
  • Fixed duplicate set_feeding_plan in 3 feeder files.
  • Fixed power_state not handling powerType=1 (DC adapter) in Dockstream 2 fountains.
  • Fixed work record query using feeder event type for fountains (now uses ["DRINK"]).
  • Fixed Device.refresh() overwriting device name with empty string from baseInfo.
  • Replaced deprecated datetime.utcnow() with datetime.now(timezone.utc) (12 occurrences).
  • Masked auth tokens in all debug log messages.

Other improvements:

  • Added diagnostics.py for device debugging support.
  • Added reconfigure flow, configuration_url, and minimum HA version (2025.4.0).
  • Device product icon shown as entity_picture on all entities.
  • Updated all 13 language translation files with new entity keys.
  • Updated validate.yml CI with scheduled runs and updated action versions.
  • Modernized type hints to use modern Python syntax throughout.

Closes # (issue)

Type of change:

  • New device.
  • Bug fix (non-breaking change which fixes an issue).
  • New feature or enhancement (non-breaking change which adds functionality).
  • Documentation only.
  • Other (please explain).

Major codebase refactor: consolidated shared device logic into base classes, removed dead code/modules, modernized API layer.

Checklist:

  • If applicable, I have added corresponding documentation changes.
  • If applicable, I have reviewed the feature / enhancement guidlines before submitting my request.
  • If applicable, I have tested my code for new features & regressions on the latest version of Home Assistant.

Additional notes:

  • Minimum Home Assistant version now set to 2025.4.0.
  • All API responses now use _cached_request() with 10-second TTL to reduce duplicate calls.
  • Entity entity_picture now shows device product icons on all entities.
  • Should work well with: https://github.com/dn5qMDW3/petlibro-cards

…nfigurations.

- Added `diagnostics.py` with diagnostic support for PETLIBRO.
- Introduced `create_platform_setup` for reducing boilerplate in platform setups.
- Consolidated duplicate setup code across select, text, updates, and number platforms.
- Refined imports and removed redundant imports for cleaner code structure.
- Added `reconfigure` flow and dependencies to `strings.json` and `manifest.json`.
- Simplified platform specification in `__init__.py`.
…into a base class (`Feeder`) and removing redundant code.
…ndling, and add new properties/sensors for fountains.
…sed attributes and adding `configuration_url`.
…ew sensors for Polar Wet Food Feeder, and refactor device-specific properties.
@jjjonesjr33 jjjonesjr33 added the Deferred put off (an action or event) to a later time; postpone label Mar 30, 2026
@jjjonesjr33 jjjonesjr33 added this to the Other milestone Mar 30, 2026
@github-project-automation github-project-automation Bot moved this to To triage in Petlibro Mar 30, 2026
@dn5qMDW3

Copy link
Copy Markdown
Author

Superseded by #212 which rebases the same DRY refactoring cleanly on top of current dev (including #201, #204, #209, #210).

@dn5qMDW3 dn5qMDW3 closed this Mar 30, 2026
@github-project-automation github-project-automation Bot moved this from To triage to Done in Petlibro Mar 30, 2026
@dn5qMDW3
dn5qMDW3 deleted the dev branch April 16, 2026 10:44
@jjjonesjr33 jjjonesjr33 added Canceled Something that will not take place and removed Deferred put off (an action or event) to a later time; postpone labels Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Canceled Something that will not take place

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants