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
This commit is contained in:
Rene Lehfeld 2021-03-02 18:57:14 +01:00 committed by GitHub
parent 4904207f77
commit 2272925699
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 0 deletions

View File

@ -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."""

View File

@ -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."""

View File

@ -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):