Skip to content

Commit a2a9e10

Browse files
fix: preserve heat settings when turning on the fireplace
`turn_on()` reads the full fire overview specifically so it can preserve existing settings, but it only ever wrote back ModeParam (321) and FlameEffectParam (322). HeatParam (323) — heat status, heat mode, setpoint temperature and boost duration — is a separate parameter and was never captured or written, so powering on left the heater state unconstrained: a fire whose heater was off could start heating as a side effect of the MANUAL mode write, while consumers deriving power state from `HeatParam.heat_status` still reported the heater as off. Capture HeatParam in the overview read `turn_on()` already performs and write it back unchanged alongside ModeParam, exactly as is already done for FlameEffectParam. The heater keeps whatever status, mode, setpoint and boost duration the fire reported. `turn_off()` is unchanged: it writes STANDBY, which stops the heater by design. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D1yvvxN11TEbSs6sMsR3K7
1 parent 1fc445c commit a2a9e10

2 files changed

Lines changed: 108 additions & 4 deletions

File tree

‎src/flameconnect/client.py‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,16 @@ async def write_parameters(self, fire_id: str, params: list[Parameter]) -> None:
309309
await self._request("POST", url, json=payload)
310310

311311
async def turn_on(self, fire_id: str) -> None:
312-
"""Turn on the fireplace, preserving current flame effect settings.
312+
"""Turn on the fireplace, preserving flame effect and heat settings.
313313
314-
Reads the current state first to preserve existing temperature and
315-
flame effect configuration, then sets the mode to MANUAL and the
316-
flame effect to ON.
314+
Reads the current state first to preserve the existing temperature,
315+
flame effect configuration and heat settings, then sets the mode to
316+
MANUAL and the flame effect to ON.
317+
318+
Heat settings (ParameterId 323) are written back unchanged so that
319+
powering on cannot start or stop the heater as a side effect: a
320+
fireplace whose heater is off stays off, and one whose heater is on
321+
keeps its status, mode, setpoint and boost duration.
317322
318323
Args:
319324
fire_id: The unique identifier of the fireplace.
@@ -323,11 +328,14 @@ async def turn_on(self, fire_id: str) -> None:
323328
# Find current ModeParam to preserve temperature
324329
current_mode: ModeParam | None = None
325330
current_flame: FlameEffectParam | None = None
331+
current_heat: HeatParam | None = None
326332
for param in overview.parameters:
327333
if isinstance(param, ModeParam):
328334
current_mode = param
329335
elif isinstance(param, FlameEffectParam):
330336
current_flame = param
337+
elif isinstance(param, HeatParam):
338+
current_heat = param
331339

332340
temperature = (
333341
current_mode.target_temperature
@@ -343,6 +351,9 @@ async def turn_on(self, fire_id: str) -> None:
343351
new_flame = replace(current_flame, flame_effect=FlameEffect.ON)
344352
params_to_write.append(new_flame)
345353

354+
if current_heat is not None:
355+
params_to_write.append(current_heat)
356+
346357
await self.write_parameters(fire_id, params_to_write)
347358

348359
async def turn_off(self, fire_id: str) -> None:

‎tests/test_client.py‎

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,99 @@ async def test_turn_on_no_flame_param_writes_only_mode(self, mock_api, token_aut
931931
assert len(body["Parameters"]) == 1
932932
assert body["Parameters"][0]["ParameterId"] == 321
933933

934+
async def test_turn_on_keeps_heat_off(self, mock_api, token_auth):
935+
"""turn_on must not start the heater when it is off.
936+
937+
Powering on writes MANUAL mode; without writing HeatSettings
938+
(323) back the heater state is left unconstrained and the fire
939+
can start heating even though the heater was off.
940+
"""
941+
fire_id = "heat-off-fire"
942+
overview_url = f"{API_BASE}/api/Fires/GetFireOverview?FireId={fire_id}"
943+
write_url = f"{API_BASE}/api/Fires/WriteWifiParameters"
944+
mode_val = encode_parameter(
945+
ModeParam(mode=FireMode.STANDBY, target_temperature=20.0)
946+
)
947+
heat_off_val = encode_parameter(
948+
HeatParam(
949+
heat_status=HeatStatus.OFF,
950+
heat_mode=HeatMode.NORMAL,
951+
setpoint_temperature=21.0,
952+
boost_duration=1,
953+
)
954+
)
955+
payload = _make_overview_payload(
956+
fire_id=fire_id,
957+
parameters=[
958+
{"ParameterId": 321, "Value": mode_val},
959+
{"ParameterId": 323, "Value": heat_off_val},
960+
],
961+
)
962+
mock_api.get(overview_url, payload=payload)
963+
mock_api.post(write_url, payload={})
964+
965+
async with FlameConnectClient(token_auth) as client:
966+
await client.turn_on(fire_id)
967+
968+
key = ("POST", URL(write_url))
969+
body = mock_api.requests[key][0].kwargs["json"]
970+
heat_wires = [p for p in body["Parameters"] if p["ParameterId"] == 323]
971+
assert heat_wires, "turn_on did not write HeatSettings (323)"
972+
raw = base64.b64decode(heat_wires[0]["Value"])
973+
# Byte 3 is heat_status: must stay 0 (OFF)
974+
assert raw[3] == HeatStatus.OFF
975+
976+
async def test_turn_on_preserves_heat_settings(
977+
self,
978+
mock_api,
979+
token_auth,
980+
get_fire_overview_payload,
981+
):
982+
"""turn_on writes the current heat settings back unchanged."""
983+
fire_id = "test-fire-001"
984+
overview_url = f"{API_BASE}/api/Fires/GetFireOverview?FireId={fire_id}"
985+
write_url = f"{API_BASE}/api/Fires/WriteWifiParameters"
986+
mock_api.get(overview_url, payload=get_fire_overview_payload)
987+
mock_api.post(write_url, payload={})
988+
989+
overview_heat = next(
990+
p
991+
for p in get_fire_overview_payload["WifiFireOverview"]["Parameters"]
992+
if p["ParameterId"] == 323
993+
)
994+
995+
async with FlameConnectClient(token_auth) as client:
996+
await client.turn_on(fire_id)
997+
998+
key = ("POST", URL(write_url))
999+
body = mock_api.requests[key][0].kwargs["json"]
1000+
heat_wires = [p for p in body["Parameters"] if p["ParameterId"] == 323]
1001+
assert heat_wires, "turn_on did not write HeatSettings (323)"
1002+
assert heat_wires[0]["Value"] == overview_heat["Value"]
1003+
1004+
async def test_turn_on_no_heat_param_writes_no_heat(self, mock_api, token_auth):
1005+
"""When the fire reports no HeatParam, none is written."""
1006+
fire_id = "no-heat-fire"
1007+
overview_url = f"{API_BASE}/api/Fires/GetFireOverview?FireId={fire_id}"
1008+
write_url = f"{API_BASE}/api/Fires/WriteWifiParameters"
1009+
mode_val = encode_parameter(
1010+
ModeParam(mode=FireMode.STANDBY, target_temperature=20.0)
1011+
)
1012+
payload = _make_overview_payload(
1013+
fire_id=fire_id,
1014+
parameters=[{"ParameterId": 321, "Value": mode_val}],
1015+
)
1016+
mock_api.get(overview_url, payload=payload)
1017+
mock_api.post(write_url, payload={})
1018+
1019+
async with FlameConnectClient(token_auth) as client:
1020+
await client.turn_on(fire_id)
1021+
1022+
key = ("POST", URL(write_url))
1023+
body = mock_api.requests[key][0].kwargs["json"]
1024+
param_ids = {p["ParameterId"] for p in body["Parameters"]}
1025+
assert 323 not in param_ids
1026+
9341027

9351028
# -------------------------------------------------------------------
9361029
# turn_off

0 commit comments

Comments
 (0)