Skip to content

Commit

Permalink
Report auto status accurately (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewturner authored Mar 1, 2024
1 parent 36337a5 commit 86df172
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 4 deletions.
17 changes: 13 additions & 4 deletions salusfy/web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ async def get_state(self) -> State:

data = await self.get_state_data()

return WebClient.convert_to_state(data)

@classmethod
def convert_to_state(cls, data: dict) -> State:
"""Converts the data payload to a state object"""
state = State()
state.target_temperature = float(data["CH1currentSetPoint"])
state.current_temperature = float(data["CH1currentRoomTemp"])
Expand All @@ -148,11 +153,15 @@ async def get_state(self) -> State:
else:
state.action = HVACAction.IDLE

mode = data['CH1heatOnOff']
if mode == "1":
state.mode = HVACMode.OFF
heat_on_off = data['CH1heatOnOff']
auto_mode = data['CH1autoMode']
if heat_on_off == "0" and auto_mode == "0":
state.mode = HVACMode.AUTO
else:
state.mode = HVACMode.HEAT
if heat_on_off == "1":
state.mode = HVACMode.OFF
else:
state.mode = HVACMode.HEAT

return state

Expand Down
67 changes: 67 additions & 0 deletions tests/test_web_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import pytest

from homeassistant.components.climate.const import (
HVACMode,
HVACAction
)

from salusfy import WebClient

@pytest.fixture
def payload() -> dict:
"""Returns the default data for the tests"""
return {
'CH1currentSetPoint': 20.1,
'CH1currentRoomTemp': 15.2,
'frost': 8.5,
'CH1heatOnOffStatus': "1",
'CH1heatOnOff': "1",
'CH1autoMode': "1"
}

def test_extract_target_temperature(payload):
actual = WebClient.convert_to_state(payload)

assert actual.target_temperature == 20.1

def test_extract_current_temperature(payload):
actual = WebClient.convert_to_state(payload)

assert actual.current_temperature == 15.2

def test_extract_frost(payload):
actual = WebClient.convert_to_state(payload)

assert actual.frost == 8.5

def test_hvac_action_is_heating(payload):
payload['CH1heatOnOffStatus'] = "1"
payload['CH1heatOnOff'] = "1"
payload['CH1autoMode'] = "1"
actual = WebClient.convert_to_state(payload)

assert actual.action == HVACAction.HEATING

def test_hvac_action_is_off(payload):
payload['CH1heatOnOffStatus'] = "0"
payload['CH1heatOnOff'] = "1"
payload['CH1autoMode'] = "1"
actual = WebClient.convert_to_state(payload)

assert actual.action == HVACAction.IDLE

def test_hvac_mode_is_off(payload):
payload['CH1heatOnOffStatus'] = "1"
payload['CH1heatOnOff'] = "1"
payload['CH1autoMode'] = "1"
actual = WebClient.convert_to_state(payload)

assert actual.mode == HVACMode.OFF

def test_hvac_mode_is_heat(payload):
payload['CH1heatOnOffStatus'] = "1"
payload['CH1heatOnOff'] = "0"
payload['CH1autoMode'] = "1"
actual = WebClient.convert_to_state(payload)

assert actual.mode == HVACMode.HEAT

0 comments on commit 86df172

Please sign in to comment.