Skip to content

Commit

Permalink
added initial load for climate
Browse files Browse the repository at this point in the history
  • Loading branch information
grimmpp committed Feb 16, 2024
1 parent 038b6a6 commit 070a383
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 30 deletions.
16 changes: 7 additions & 9 deletions custom_components/eltako/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,14 @@ def load_value_initially(self, latest_state:State):
if m_str == m_enum.value:
self.hvac_modes.append(m_enum)

self._attr_current_temperature = float(latest_state.attributes.get('current_temperature', None) )
self._attr_target_temperature = float(latest_state.attributes.get('temperature', None) )
self._attr_current_temperature = latest_state.attributes.get('current_temperature', None)
self._attr_target_temperature = latest_state.attributes.get('temperature', None)

if 'unknown' == latest_state.state:
self._attr_hvac_mode = None
else:
for m_enum in HVACMode:
if latest_state.state == m_enum.value:
self._attr_hvac_mode = m_enum
break
self._attr_hvac_mode = None
for m_enum in HVACMode:
if latest_state.state == m_enum.value:
self._attr_hvac_mode = m_enum
break

except Exception as e:
self._attr_hvac_mode = None
Expand Down
47 changes: 26 additions & 21 deletions tests/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,31 @@ def test_climate_cooling_switch(self):
# self.assertEquals(cc._actuator_mode, A5_10_06.Heater_Mode.NORMAL);
# self.assertEquals( round(cc.current_temperature), current_temperature)
# self.assertEquals( round(cc.target_temperature), target_temp)


def test_initial_loading(self):
cc = create_climate_entity()

cc.load_value_initially(LatestStateMock('heat',
attributes={'hvac_modes': ['heat', 'off'],
'min_temp': 17,
'max_temp': 25,
'current_temperature': 19.8,
'temperature': 22.5,
'friendly_name': 'Bad Room',
'supported_features': 385}))
self.assertEqual(cc.current_temperature, 19.8)
self.assertEqual(cc.target_temperature, 22.5)
self.assertEqual(cc.state, 'heat')


def test_initial_loading_None(self):
cc = create_climate_entity()

cc.load_value_initially(LatestStateMock(None))
self.assertEqual(cc.current_temperature, None)
self.assertEqual(cc.target_temperature, None)
self.assertEqual(cc.state, None)

class TestClimateAsync(unittest.IsolatedAsyncioTestCase):

Expand Down Expand Up @@ -143,24 +168,4 @@ async def test_climate_cooling_switch(self):
msg = F6_02_01(3, 1, 0, 0).encode_message(b'\xFF\xFF\xFF\x01')
# cc.value_changed(msg)
await cc.async_handle_event(EventDataMock({'switch_address': cooling_switch.id, 'data': cooling_switch[CONF_SWITCH_BUTTON]}))
self.assertEquals(cc.hvac_mode, HVACMode.COOL)

# class TestClimateInitialLoading(unittest.TestCase):

# def test_initial_loading(self):
# cc = create_climate_entity()
# cc._attr_native_value = None

# cc.load_value_initially(LatestStateMock('25.5'))
# self.assertEquals(cc._attr_native_value, 25.5)
# self.assertEquals(cc.native_value, 25.5)
# self.assertEquals(cc.state, '25.5')


# def test_initial_loading_None(self):
# cc = create_climate_entity()
# cc._attr_native_value = 25.5

# cc.load_value_initially(LatestStateMock('unknown'))
# self.assertIsNone(cc._attr_native_value)
# self.assertIsNone(cc.state)
self.assertEquals(cc.hvac_mode, HVACMode.COOL)

0 comments on commit 070a383

Please sign in to comment.