mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
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:
parent
4904207f77
commit
2272925699
@ -192,6 +192,11 @@ class TasmotaSensor(TasmotaAvailability, TasmotaDiscoveryUpdate, Entity):
|
|||||||
return self._state.isoformat()
|
return self._state.isoformat()
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
|
@property
|
||||||
|
def force_update(self):
|
||||||
|
"""Force update."""
|
||||||
|
return True
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Return the unit this state is expressed in."""
|
"""Return the unit this state is expressed in."""
|
||||||
|
@ -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")
|
state = hass.states.get("binary_sensor.tasmota_binary_sensor_1")
|
||||||
assert state.state == STATE_OFF
|
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):
|
async def test_controlling_state_via_mqtt_switchname(hass, mqtt_mock, setup_tasmota):
|
||||||
"""Test state update via MQTT."""
|
"""Test state update via MQTT."""
|
||||||
|
@ -275,6 +275,12 @@ async def test_status_sensor_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
|||||||
state = hass.states.get("sensor.tasmota_status")
|
state = hass.states.get("sensor.tasmota_status")
|
||||||
assert state.state == "20.0"
|
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])
|
@pytest.mark.parametrize("status_sensor_disabled", [False])
|
||||||
async def test_single_shot_status_sensor_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
async def test_single_shot_status_sensor_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user