Skip to content

Commit bb2d7d4

Browse files
committed
deprecate the old API regarding switches
1 parent 1abc3c1 commit bb2d7d4

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

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
@@ -709,6 +711,7 @@ async def get_accessories(self):
709711
# {"code":200,"message":"Query success!","result":[],"success":true,"total":0}
710712
return (await self._get(url))["result"]
711713

714+
@deprecated("use get_smart_circuits() instead")
712715
async def get_smart_switch_state(self) -> SwitchState:
713716
"""Get the current state of the smart switches."""
714717
# TODO(richo) This API is super in flux, both because of how vague the
@@ -720,6 +723,7 @@ async def get_smart_switch_state(self) -> SwitchState:
720723
switches = [x == 1 for x in status["pro_load"]]
721724
return SwitchState(switches)
722725

726+
@deprecated("use set_circuit() instead")
723727
async def set_smart_switch_state(self, state: SwitchState):
724728
"""Set the state of the smart circuits.
725729
@@ -766,6 +770,7 @@ async def _status(self):
766770
return json.loads(data)
767771

768772
# Sends a 311 which appears to be a more specific switch command
773+
@deprecated("use get_smart_circuits() or get_smart_circuits_enhanced() instead")
769774
@time_cached()
770775
async def _switch_status(self):
771776
payload = self._build_payload(311, {"opt": 0, "order": self.gateway})
@@ -774,6 +779,7 @@ async def _switch_status(self):
774779

775780
# Sends a 353 which grabs real-time smart-circuit load information
776781
# https://github.com/richo/homeassistant-franklinwh/issues/27#issuecomment-2714422732
782+
@deprecated("use get_smart_circuits_enhanced() instead")
777783
@time_cached()
778784
async def _switch_usage(self):
779785
payload = self._build_payload(353, {"opt": 0, "order": self.gateway})
@@ -812,6 +818,11 @@ async def get_stats(self) -> Stats:
812818
813819
This includes instantaneous measurements for current power, as well as totals for today (in local time)
814820
"""
821+
warn(
822+
"switch statistics are deprecated from get_stats(), use get_smart_circuits_enhanced() instead",
823+
DeprecationWarning,
824+
stacklevel=2,
825+
)
815826
tasks = [f() for f in [self.get_composite_info, self._switch_usage]]
816827
info, sw_data = await asyncio.gather(*tasks)
817828
data = info["runtimeData"]

0 commit comments

Comments
 (0)