Skip to content

Commit efdbfcf

Browse files
committed
deprecate the old API regarding switches
1 parent 7b06ea8 commit efdbfcf

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

franklinwh/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
Mode,
1515
SmartCircuits,
1616
Stats,
17-
SwitchState,
17+
SwitchState, # deprecated
1818
TokenFetcher,
1919
)
2020

@@ -32,6 +32,6 @@
3232
"Mode",
3333
"SmartCircuits",
3434
"Stats",
35-
"SwitchState",
35+
"SwitchState", # deprecated
3636
"TokenFetcher",
3737
]

franklinwh/client.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import logging
1717
import time
1818
from typing import Any
19+
from warnings import deprecated, warn
1920
import zlib
2021

2122
import httpx
@@ -189,9 +190,9 @@ class Current:
189190
grid_use: float
190191
home_load: float
191192
battery_soc: float
192-
switch_1_load: float
193-
switch_2_load: float
194-
v2l_use: float
193+
switch_1_load: float # deprecated
194+
switch_2_load: float # deprecated
195+
v2l_use: float # deprecated
195196
grid_status: GridStatus
196197

197198

@@ -206,10 +207,10 @@ class Totals:
206207
solar: float
207208
generator: float
208209
home_use: float
209-
switch_1_use: float
210-
switch_2_use: float
211-
v2l_export: float
212-
v2l_import: float
210+
switch_1_use: float # deprecated
211+
switch_2_use: float # deprecated
212+
v2l_export: float # deprecated
213+
v2l_import: float # deprecated
213214

214215

215216
@dataclass
@@ -351,6 +352,7 @@ def payload(self, gateway) -> dict:
351352
}
352353

353354

355+
@deprecated("use SmartCircuits instead")
354356
class SwitchState(tuple[bool | None, bool | None, bool | None]):
355357
"""Represents the state of the smart switches connected to the FranklinWH gateway.
356358
@@ -679,6 +681,7 @@ async def get_accessories(self):
679681
# {"code":200,"message":"Query success!","result":[],"success":true,"total":0}
680682
return (await self._get(url))["result"]
681683

684+
@deprecated("use get_smart_circuits() instead")
682685
async def get_smart_switch_state(self) -> SwitchState:
683686
"""Get the current state of the smart switches."""
684687
# TODO(richo) This API is super in flux, both because of how vague the
@@ -690,6 +693,7 @@ async def get_smart_switch_state(self) -> SwitchState:
690693
switches = [x == 1 for x in status["pro_load"]]
691694
return SwitchState(switches)
692695

696+
@deprecated("use set_circuit() instead")
693697
async def set_smart_switch_state(self, state: SwitchState):
694698
"""Set the state of the smart circuits.
695699
@@ -736,6 +740,7 @@ async def _status(self):
736740
return json.loads(data)
737741

738742
# Sends a 311 which appears to be a more specific switch command
743+
@deprecated("use get_smart_circuits() or get_smart_circuits_enhanced() instead")
739744
@time_cached()
740745
async def _switch_status(self):
741746
payload = self._build_payload(311, {"opt": 0, "order": self.gateway})
@@ -744,6 +749,7 @@ async def _switch_status(self):
744749

745750
# Sends a 353 which grabs real-time smart-circuit load information
746751
# https://github.com/richo/homeassistant-franklinwh/issues/27#issuecomment-2714422732
752+
@deprecated("use get_smart_circuits_enhanced() instead")
747753
@time_cached()
748754
async def _switch_usage(self):
749755
payload = self._build_payload(353, {"opt": 0, "order": self.gateway})
@@ -782,6 +788,11 @@ async def get_stats(self) -> Stats:
782788
783789
This includes instantaneous measurements for current power, as well as totals for today (in local time)
784790
"""
791+
warn(
792+
"switch statistics are deprecated from get_stats(), use get_smart_circuits_enhanced() instead",
793+
DeprecationWarning,
794+
stacklevel=2,
795+
)
785796
tasks = [f() for f in [self.get_composite_info, self._switch_usage]]
786797
info, sw_data = await asyncio.gather(*tasks)
787798
data = info["runtimeData"]

0 commit comments

Comments
 (0)