From 227292569936408475a8d169e4e54f4d1beeb16f Mon Sep 17 00:00:00 2001 From: Rene Lehfeld <54720674+rlehfeld@users.noreply.github.com> Date: Tue, 2 Mar 2021 18:57:14 +0100 Subject: [PATCH] Add force_update to tasmota sensors (#47052) * Add force update also to non-binary sensors as e.g. POWER Measurement agerage cannot be calculated otherwise. This is the same behavior as set with the obsolete tasmota detection * add tests in binary_sensor and test_sensor for force_update flag * satisfy flake8 * next try for force_update test but this time on the entity object which is the correct level * once again satisfy flake8 * one more try for a test * fix typo * satisfy black --- homeassistant/components/tasmota/sensor.py | 5 +++++ tests/components/tasmota/test_binary_sensor.py | 6 ++++++ tests/components/tasmota/test_sensor.py | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/homeassistant/components/tasmota/sensor.py b/homeassistant/components/tasmota/sensor.py index 17a6e2a35c2..39577e9e558 100644 --- a/homeassistant/components/tasmota/sensor.py +++ b/homeassistant/components/tasmota/sensor.py @@ -192,6 +192,11 @@ class TasmotaSensor(TasmotaAvailability, TasmotaDiscoveryUpdate, Entity): return self._state.isoformat() return self._state + @property + def force_update(self): + """Force update.""" + return True + @property def unit_of_measurement(self): """Return the unit this state is expressed in.""" diff --git a/tests/components/tasmota/test_binary_sensor.py b/tests/components/tasmota/test_binary_sensor.py index 6d4263853dc..6b13dcc89ec 100644 --- a/tests/components/tasmota/test_binary_sensor.py +++ b/tests/components/tasmota/test_binary_sensor.py @@ -95,6 +95,12 @@ async def test_controlling_state_via_mqtt(hass, mqtt_mock, setup_tasmota): state = hass.states.get("binary_sensor.tasmota_binary_sensor_1") assert state.state == STATE_OFF + # Test force update flag + entity = hass.data["entity_components"]["binary_sensor"].get_entity( + "binary_sensor.tasmota_binary_sensor_1" + ) + assert entity.force_update + async def test_controlling_state_via_mqtt_switchname(hass, mqtt_mock, setup_tasmota): """Test state update via MQTT.""" diff --git a/tests/components/tasmota/test_sensor.py b/tests/components/tasmota/test_sensor.py index fe415c264ef..6e5160273d6 100644 --- a/tests/components/tasmota/test_sensor.py +++ b/tests/components/tasmota/test_sensor.py @@ -275,6 +275,12 @@ async def test_status_sensor_state_via_mqtt(hass, mqtt_mock, setup_tasmota): state = hass.states.get("sensor.tasmota_status") assert state.state == "20.0" + # Test force update flag + entity = hass.data["entity_components"]["sensor"].get_entity( + "sensor.tasmota_status" + ) + assert entity.force_update + @pytest.mark.parametrize("status_sensor_disabled", [False]) async def test_single_shot_status_sensor_state_via_mqtt(hass, mqtt_mock, setup_tasmota):