瀏覽代碼

v2.3.2: fix fetch_settings alias + add missing set_* control methods

- api.py: add fetch_settings = get_device_settings class alias
- api.py: add set_operating_mode, set_battery_priority, set_grid_charging,
          set_grid_feed_in, set_backup_mode as update_device_settings wrappers
- manifest.json: version 2.3.2
- CHANGELOG.md: document fixes

These methods were called by __init__.py (fetch_settings), select.py, and
switch.py but did not exist on SolarOfThingsAPI, causing AttributeError on
every coordinator update.
conexocasa 7 月之前
父節點
當前提交
cec6ab8905
共有 3 個文件被更改,包括 37 次插入 和 2 次删除
  1. 12 0
      CHANGELOG.md
  2. 24 1
      api.py
  3. 1 1
      manifest.json

+ 12 - 0
CHANGELOG.md

@@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
+## [2.3.2] - 2026-03-07
+
+### Fixed
+- **`fetch_settings` AttributeError** -- `__init__.py` called `api.fetch_settings()`
+  but `api.py` only exposed `get_device_settings()`. Added `fetch_settings` as a
+  class-level alias so both names work.
+- **Missing control helper methods** -- `select.py` and `switch.py` called five
+  methods that did not exist on `SolarOfThingsAPI`:
+  `set_operating_mode`, `set_battery_priority`, `set_grid_charging`,
+  `set_grid_feed_in`, `set_backup_mode`. All five are now implemented as thin
+  wrappers over `update_device_settings`.
+
 ## [2.3.1] - 2026-03-07
 
 ### Fixed

+ 24 - 1
api.py

@@ -719,6 +719,9 @@ class SolarOfThingsAPI:
             )
         return data.get("data") or {}
 
+    # Alias used by the coordinator in __init__.py
+    fetch_settings = get_device_settings
+
     def update_device_settings(self, device_id: str, settings: dict[str, Any]) -> None:
         """Update one or more device settings."""
         payload = {"deviceId": device_id, **settings}
@@ -729,7 +732,27 @@ class SolarOfThingsAPI:
                 f"message={data.get('message')}"
             )
 
-    # ─── Connection test ───────────────────────────────────────────────────────
+    # ─── Convenience control helpers (called by select.py / switch.py) ─────────
+
+    def set_operating_mode(self, device_id: str, mode: str) -> None:
+        """Set the inverter operating mode (e.g. 'Self-Use', 'Backup')."""
+        self.update_device_settings(device_id, {"operatingMode": mode})
+
+    def set_battery_priority(self, device_id: str, mode: str) -> None:
+        """Set battery charging priority (e.g. 'Solar First', 'Grid First')."""
+        self.update_device_settings(device_id, {"batteryPriority": mode})
+
+    def set_grid_charging(self, device_id: str, enabled: bool) -> None:
+        """Enable or disable grid charging."""
+        self.update_device_settings(device_id, {"gridChargingEnabled": enabled})
+
+    def set_grid_feed_in(self, device_id: str, enabled: bool) -> None:
+        """Enable or disable grid feed-in (export)."""
+        self.update_device_settings(device_id, {"gridFeedInEnabled": enabled})
+
+    def set_backup_mode(self, device_id: str, enabled: bool) -> None:
+        """Enable or disable backup (reserve) mode."""
+        self.update_device_settings(device_id, {"backupModeEnabled": enabled})
 
     def test_connection(self, station_id: str) -> bool:
         """Return True if we can reach the device-list endpoint successfully."""

+ 1 - 1
manifest.json

@@ -9,5 +9,5 @@
   "requirements": [
     "pycryptodome>=3.9.0"
   ],
-  "version": "2.3.1"
+  "version": "2.3.2"
 }