Cleanup redundant mqtt entity constructors (#100939)

* Remove redundant mqtt entity constructors

* Remove unrelated change

* Follow up comment

* Revert changes to mqtt update platform

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Jan Bouwhuis 2023-09-26 23:03:11 +02:00 committed by GitHub
parent d387308f3c
commit 59a26010ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 27 additions and 275 deletions

View file

@ -158,16 +158,6 @@ class MqttAlarm(MqttEntity, alarm.AlarmControlPanelEntity):
_entity_id_format = alarm.ENTITY_ID_FORMAT
_attributes_extra_blocked = MQTT_ALARM_ATTRIBUTES_BLOCKED
def __init__(
self,
hass: HomeAssistant,
config: ConfigType,
config_entry: ConfigEntry,
discovery_data: DiscoveryInfoType | None,
) -> None:
"""Init the MQTT Alarm Control Panel."""
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
@staticmethod
def config_schema() -> vol.Schema:
"""Return the config schema."""

View file

@ -98,22 +98,11 @@ class MqttBinarySensor(MqttEntity, BinarySensorEntity, RestoreEntity):
"""Representation a binary sensor that is updated by MQTT."""
_default_name = DEFAULT_NAME
_delay_listener: CALLBACK_TYPE | None = None
_entity_id_format = binary_sensor.ENTITY_ID_FORMAT
_expired: bool | None
_expire_after: int | None
def __init__(
self,
hass: HomeAssistant,
config: ConfigType,
config_entry: ConfigEntry,
discovery_data: DiscoveryInfoType | None,
) -> None:
"""Initialize the MQTT binary sensor."""
self._expiration_trigger: CALLBACK_TYPE | None = None
self._delay_listener: CALLBACK_TYPE | None = None
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
_expiration_trigger: CALLBACK_TYPE | None = None
async def mqtt_async_added_to_hass(self) -> None:
"""Restore state for entities with expire_after set."""

View file

@ -73,16 +73,6 @@ class MqttButton(MqttEntity, ButtonEntity):
_default_name = DEFAULT_NAME
_entity_id_format = button.ENTITY_ID_FORMAT
def __init__(
self,
hass: HomeAssistant,
config: ConfigType,
config_entry: ConfigEntry,
discovery_data: DiscoveryInfoType | None,
) -> None:
"""Initialize the MQTT button."""
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
@staticmethod
def config_schema() -> vol.Schema:
"""Return the config schema."""

View file

@ -84,6 +84,7 @@ class MqttCamera(MqttEntity, Camera):
_default_name = DEFAULT_NAME
_entity_id_format: str = camera.ENTITY_ID_FORMAT
_attributes_extra_blocked: frozenset[str] = MQTT_CAMERA_ATTRIBUTES_BLOCKED
_last_image: bytes | None = None
def __init__(
self,
@ -93,8 +94,6 @@ class MqttCamera(MqttEntity, Camera):
discovery_data: DiscoveryInfoType | None,
) -> None:
"""Initialize the MQTT Camera."""
self._last_image: bytes | None = None
Camera.__init__(self)
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)

View file

@ -424,28 +424,16 @@ class MqttTemperatureControlEntity(MqttEntity, ABC):
climate and water_heater platforms.
"""
_attr_target_temperature_low: float | None
_attr_target_temperature_high: float | None
_attr_target_temperature_low: float | None = None
_attr_target_temperature_high: float | None = None
_feature_preset_mode: bool = False
_optimistic: bool
_topic: dict[str, Any]
_command_templates: dict[str, Callable[[PublishPayloadType], PublishPayloadType]]
_value_templates: dict[str, Callable[[ReceivePayloadType], ReceivePayloadType]]
def __init__(
self,
hass: HomeAssistant,
config: ConfigType,
config_entry: ConfigEntry,
discovery_data: DiscoveryInfoType | None,
) -> None:
"""Initialize the temperature controlled device."""
self._attr_target_temperature_low = None
self._attr_target_temperature_high = None
self._feature_preset_mode = False
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
def add_subscription(
self,
topics: dict[str, dict[str, Any]],
@ -619,27 +607,14 @@ class MqttTemperatureControlEntity(MqttEntity, ABC):
class MqttClimate(MqttTemperatureControlEntity, ClimateEntity):
"""Representation of an MQTT climate device."""
_attr_fan_mode: str | None = None
_attr_hvac_mode: HVACMode | None = None
_attr_is_aux_heat: bool | None = None
_attr_swing_mode: str | None = None
_default_name = DEFAULT_NAME
_entity_id_format = climate.ENTITY_ID_FORMAT
_attributes_extra_blocked = MQTT_CLIMATE_ATTRIBUTES_BLOCKED
def __init__(
self,
hass: HomeAssistant,
config: ConfigType,
config_entry: ConfigEntry,
discovery_data: DiscoveryInfoType | None,
) -> None:
"""Initialize the climate device."""
self._attr_fan_mode = None
self._attr_hvac_action = None
self._attr_hvac_mode = None
self._attr_is_aux_heat = None
self._attr_swing_mode = None
MqttTemperatureControlEntity.__init__(
self, hass, config, config_entry, discovery_data
)
@staticmethod
def config_schema() -> vol.Schema:
"""Return the config schema."""

View file

@ -107,19 +107,9 @@ class MqttDeviceTracker(MqttEntity, TrackerEntity):
_default_name = None
_entity_id_format = device_tracker.ENTITY_ID_FORMAT
_location_name: str | None = None
_value_template: Callable[..., ReceivePayloadType]
def __init__(
self,
hass: HomeAssistant,
config: ConfigType,
config_entry: ConfigEntry,
discovery_data: DiscoveryInfoType | None,
) -> None:
"""Initialize the tracker."""
self._location_name: str | None = None
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
@staticmethod
def config_schema() -> vol.Schema:
"""Return the config schema."""

View file

@ -108,16 +108,6 @@ class MqttEvent(MqttEntity, EventEntity):
_attributes_extra_blocked = MQTT_EVENT_ATTRIBUTES_BLOCKED
_template: Callable[[ReceivePayloadType, PayloadSentinel], ReceivePayloadType]
def __init__(
self,
hass: HomeAssistant,
config: ConfigType,
config_entry: ConfigEntry,
discovery_data: DiscoveryInfoType | None,
) -> None:
"""Initialize the sensor."""
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
@staticmethod
def config_schema() -> vol.Schema:
"""Return the config schema."""

View file

@ -220,6 +220,9 @@ async def _async_setup_entity(
class MqttFan(MqttEntity, FanEntity):
"""A MQTT fan component."""
_attr_percentage: int | None = None
_attr_preset_mode: str | None = None
_default_name = DEFAULT_NAME
_entity_id_format = fan.ENTITY_ID_FORMAT
_attributes_extra_blocked = MQTT_FAN_ATTRIBUTES_BLOCKED
@ -237,19 +240,6 @@ class MqttFan(MqttEntity, FanEntity):
_payload: dict[str, Any]
_speed_range: tuple[int, int]
def __init__(
self,
hass: HomeAssistant,
config: ConfigType,
config_entry: ConfigEntry,
discovery_data: DiscoveryInfoType | None,
) -> None:
"""Initialize the MQTT fan."""
self._attr_percentage = None
self._attr_preset_mode = None
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
@staticmethod
def config_schema() -> vol.Schema:
"""Return the config schema."""

View file

@ -212,6 +212,7 @@ async def _async_setup_entity(
class MqttHumidifier(MqttEntity, HumidifierEntity):
"""A MQTT humidifier component."""
_attr_mode: str | None = None
_default_name = DEFAULT_NAME
_entity_id_format = humidifier.ENTITY_ID_FORMAT
_attributes_extra_blocked = MQTT_HUMIDIFIER_ATTRIBUTES_BLOCKED
@ -224,18 +225,6 @@ class MqttHumidifier(MqttEntity, HumidifierEntity):
_payload: dict[str, str]
_topic: dict[str, Any]
def __init__(
self,
hass: HomeAssistant,
config: ConfigType,
config_entry: ConfigEntry,
discovery_data: DiscoveryInfoType | None,
) -> None:
"""Initialize the MQTT humidifier."""
self._attr_mode = None
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
@staticmethod
def config_schema() -> vol.Schema:
"""Return the config schema."""

View file

@ -119,17 +119,6 @@ class MqttLawnMower(MqttEntity, LawnMowerEntity, RestoreEntity):
_command_topics: dict[str, str]
_value_template: Callable[[ReceivePayloadType], ReceivePayloadType]
def __init__(
self,
hass: HomeAssistant,
config: ConfigType,
config_entry: ConfigEntry,
discovery_data: DiscoveryInfoType | None,
) -> None:
"""Initialize the MQTT lawn mower."""
LawnMowerEntity.__init__(self)
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
@staticmethod
def config_schema() -> vol.Schema:
"""Return the config schema."""

View file

@ -264,16 +264,6 @@ class MqttLight(MqttEntity, LightEntity, RestoreEntity):
_optimistic_rgbww_color: bool
_optimistic_xy_color: bool
def __init__(
self,
hass: HomeAssistant,
config: ConfigType,
config_entry: ConfigEntry,
discovery_data: DiscoveryInfoType | None,
) -> None:
"""Initialize MQTT light."""
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
@staticmethod
def config_schema() -> vol.Schema:
"""Return the config schema."""

View file

@ -184,21 +184,11 @@ class MqttLightJson(MqttEntity, LightEntity, RestoreEntity):
_entity_id_format = ENTITY_ID_FORMAT
_attributes_extra_blocked = MQTT_LIGHT_ATTRIBUTES_BLOCKED
_fixed_color_mode: ColorMode | str | None = None
_flash_times: dict[str, int | None]
_topic: dict[str, str | None]
_optimistic: bool
def __init__(
self,
hass: HomeAssistant,
config: ConfigType,
config_entry: ConfigEntry,
discovery_data: DiscoveryInfoType | None,
) -> None:
"""Initialize MQTT JSON light."""
self._fixed_color_mode: ColorMode | str | None = None
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
@staticmethod
def config_schema() -> vol.Schema:
"""Return the config schema."""

View file

@ -138,16 +138,6 @@ class MqttLightTemplate(MqttEntity, LightEntity, RestoreEntity):
_fixed_color_mode: ColorMode | str | None
_topics: dict[str, str | None]
def __init__(
self,
hass: HomeAssistant,
config: ConfigType,
config_entry: ConfigEntry,
discovery_data: DiscoveryInfoType | None,
) -> None:
"""Initialize a MQTT Template light."""
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
@staticmethod
def config_schema() -> vol.Schema:
"""Return the config schema."""

View file

@ -142,16 +142,6 @@ class MqttLock(MqttEntity, LockEntity):
]
_value_template: Callable[[ReceivePayloadType], ReceivePayloadType]
def __init__(
self,
hass: HomeAssistant,
config: ConfigType,
config_entry: ConfigEntry,
discovery_data: DiscoveryInfoType | None,
) -> None:
"""Initialize the lock."""
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
@staticmethod
def config_schema() -> vol.Schema:
"""Return the config schema."""

View file

@ -146,17 +146,6 @@ class MqttNumber(MqttEntity, RestoreNumber):
_command_template: Callable[[PublishPayloadType], PublishPayloadType]
_value_template: Callable[[ReceivePayloadType], ReceivePayloadType]
def __init__(
self,
hass: HomeAssistant,
config: ConfigType,
config_entry: ConfigEntry,
discovery_data: DiscoveryInfoType | None,
) -> None:
"""Initialize the MQTT Number."""
RestoreNumber.__init__(self)
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
@staticmethod
def config_schema() -> vol.Schema:
"""Return the config schema."""

View file

@ -69,16 +69,6 @@ class MqttScene(
_default_name = DEFAULT_NAME
_entity_id_format = scene.DOMAIN + ".{}"
def __init__(
self,
hass: HomeAssistant,
config: ConfigType,
config_entry: ConfigEntry,
discovery_data: DiscoveryInfoType | None,
) -> None:
"""Initialize the MQTT scene."""
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
@staticmethod
def config_schema() -> vol.Schema:
"""Return the config schema."""

View file

@ -93,6 +93,7 @@ async def _async_setup_entity(
class MqttSelect(MqttEntity, SelectEntity, RestoreEntity):
"""representation of an MQTT select."""
_attr_current_option: str | None = None
_default_name = DEFAULT_NAME
_entity_id_format = select.ENTITY_ID_FORMAT
_attributes_extra_blocked = MQTT_SELECT_ATTRIBUTES_BLOCKED
@ -100,18 +101,6 @@ class MqttSelect(MqttEntity, SelectEntity, RestoreEntity):
_value_template: Callable[[ReceivePayloadType], ReceivePayloadType]
_optimistic: bool = False
def __init__(
self,
hass: HomeAssistant,
config: ConfigType,
config_entry: ConfigEntry,
discovery_data: DiscoveryInfoType | None,
) -> None:
"""Initialize the MQTT select."""
self._attr_current_option = None
SelectEntity.__init__(self)
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
@staticmethod
def config_schema() -> vol.Schema:
"""Return the config schema."""

View file

@ -130,22 +130,12 @@ class MqttSensor(MqttEntity, RestoreSensor):
_entity_id_format = ENTITY_ID_FORMAT
_attr_last_reset: datetime | None = None
_attributes_extra_blocked = MQTT_SENSOR_ATTRIBUTES_BLOCKED
_expiration_trigger: CALLBACK_TYPE | None = None
_expire_after: int | None
_expired: bool | None
_template: Callable[[ReceivePayloadType, PayloadSentinel], ReceivePayloadType]
_last_reset_template: Callable[[ReceivePayloadType], ReceivePayloadType]
def __init__(
self,
hass: HomeAssistant,
config: ConfigType,
config_entry: ConfigEntry,
discovery_data: DiscoveryInfoType | None,
) -> None:
"""Initialize the sensor."""
self._expiration_trigger: CALLBACK_TYPE | None = None
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
async def mqtt_async_added_to_hass(self) -> None:
"""Restore state for entities with expire_after set."""
last_state: State | None

View file

@ -155,16 +155,6 @@ class MqttSiren(MqttEntity, SirenEntity):
_state_off: str
_optimistic: bool
def __init__(
self,
hass: HomeAssistant,
config: ConfigType,
config_entry: ConfigEntry,
discovery_data: DiscoveryInfoType | None,
) -> None:
"""Initialize the MQTT siren."""
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
@staticmethod
def config_schema() -> vol.Schema:
"""Return the config schema."""

View file

@ -100,17 +100,6 @@ class MqttSwitch(MqttEntity, SwitchEntity, RestoreEntity):
_state_off: str
_value_template: Callable[[ReceivePayloadType], ReceivePayloadType]
def __init__(
self,
hass: HomeAssistant,
config: ConfigType,
config_entry: ConfigEntry,
discovery_data: DiscoveryInfoType | None,
) -> None:
"""Initialize the MQTT switch."""
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
@staticmethod
def config_schema() -> vol.Schema:
"""Return the config schema."""

View file

@ -128,6 +128,7 @@ async def _async_setup_entity(
class MqttTextEntity(MqttEntity, TextEntity):
"""Representation of the MQTT text entity."""
_attr_native_value: str | None = None
_attributes_extra_blocked = MQTT_TEXT_ATTRIBUTES_BLOCKED
_default_name = DEFAULT_NAME
_entity_id_format = text.ENTITY_ID_FORMAT
@ -137,17 +138,6 @@ class MqttTextEntity(MqttEntity, TextEntity):
_command_template: Callable[[PublishPayloadType], PublishPayloadType]
_value_template: Callable[[ReceivePayloadType], ReceivePayloadType]
def __init__(
self,
hass: HomeAssistant,
config: ConfigType,
config_entry: ConfigEntry,
discovery_data: DiscoveryInfoType | None = None,
) -> None:
"""Initialize MQTT text entity."""
self._attr_native_value = None
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
@staticmethod
def config_schema() -> vol.Schema:
"""Return the config schema."""

View file

@ -215,12 +215,17 @@ async def async_setup_entity_legacy(
class MqttVacuum(MqttEntity, VacuumEntity):
"""Representation of a MQTT-controlled legacy vacuum."""
_attr_battery_level = 0
_attr_is_on = False
_attributes_extra_blocked = MQTT_LEGACY_VACUUM_ATTRIBUTES_BLOCKED
_charging: bool = False
_cleaning: bool = False
_command_topic: str | None
_docked: bool = False
_default_name = DEFAULT_NAME
_entity_id_format = ENTITY_ID_FORMAT
_attributes_extra_blocked = MQTT_LEGACY_VACUUM_ATTRIBUTES_BLOCKED
_command_topic: str | None
_encoding: str | None
_error: str | None = None
_qos: bool
_retain: bool
_payloads: dict[str, str]
@ -231,25 +236,6 @@ class MqttVacuum(MqttEntity, VacuumEntity):
str, Callable[[ReceivePayloadType, PayloadSentinel], ReceivePayloadType]
]
def __init__(
self,
hass: HomeAssistant,
config: ConfigType,
config_entry: ConfigEntry,
discovery_data: DiscoveryInfoType | None,
) -> None:
"""Initialize the vacuum."""
self._attr_battery_level = 0
self._attr_is_on = False
self._attr_fan_speed = "unknown"
self._charging = False
self._cleaning = False
self._docked = False
self._error: str | None = None
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
@staticmethod
def config_schema() -> vol.Schema:
"""Return the config schema."""

View file

@ -194,18 +194,6 @@ class MqttWaterHeater(MqttTemperatureControlEntity, WaterHeaterEntity):
_entity_id_format = water_heater.ENTITY_ID_FORMAT
_attributes_extra_blocked = MQTT_WATER_HEATER_ATTRIBUTES_BLOCKED
def __init__(
self,
hass: HomeAssistant,
config: ConfigType,
config_entry: ConfigEntry,
discovery_data: DiscoveryInfoType | None,
) -> None:
"""Initialize the water heater device."""
MqttTemperatureControlEntity.__init__(
self, hass, config, config_entry, discovery_data
)
@staticmethod
def config_schema() -> vol.Schema:
"""Return the config schema."""