diff --git a/custom_components/eltako/climate.py b/custom_components/eltako/climate.py index cdb66a9..0f42608 100644 --- a/custom_components/eltako/climate.py +++ b/custom_components/eltako/climate.py @@ -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 diff --git a/tests/test_climate.py b/tests/test_climate.py index b4aa872..7a904aa 100644 --- a/tests/test_climate.py +++ b/tests/test_climate.py @@ -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): @@ -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) \ No newline at end of file + self.assertEquals(cc.hvac_mode, HVACMode.COOL) \ No newline at end of file