Use _attr_force_update in mqtt (#77902)

pull/78011/head
epenet 2022-09-07 23:42:16 +02:00 committed by GitHub
parent 52c8c80f91
commit f62fbbe524
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 10 deletions

View File

@ -184,6 +184,7 @@ class MqttBinarySensor(MqttEntity, BinarySensorEntity, RestoreEntity):
return DISCOVERY_SCHEMA
def _setup_from_config(self, config):
self._attr_force_update = config[CONF_FORCE_UPDATE]
self._value_template = MqttValueTemplate(
self._config.get(CONF_VALUE_TEMPLATE),
entity=self,
@ -300,11 +301,6 @@ class MqttBinarySensor(MqttEntity, BinarySensorEntity, RestoreEntity):
"""Return the class of this sensor."""
return self._config.get(CONF_DEVICE_CLASS)
@property
def force_update(self) -> bool:
"""Force update."""
return self._config[CONF_FORCE_UPDATE]
@property
def available(self) -> bool:
"""Return true if the device is available and value has not expired."""

View File

@ -233,6 +233,7 @@ class MqttSensor(MqttEntity, RestoreSensor):
def _setup_from_config(self, config):
"""(Re)Setup the entity."""
self._attr_force_update = config[CONF_FORCE_UPDATE]
self._template = MqttValueTemplate(
self._config.get(CONF_VALUE_TEMPLATE), entity=self
).async_render_with_possible_json_value
@ -350,11 +351,6 @@ class MqttSensor(MqttEntity, RestoreSensor):
"""Return the unit this state is expressed in."""
return self._config.get(CONF_UNIT_OF_MEASUREMENT)
@property
def force_update(self) -> bool:
"""Force update."""
return self._config[CONF_FORCE_UPDATE]
@property
def native_value(self):
"""Return the state of the entity."""