Improve MQTT test coverage and remove dead code (#33584)
* Improve MQTT tests and remove dead code * Remove useless test. * Add more test
This commit is contained in:
1 parent
a813847f6e
commit
4e6fd19624
12 files changed
+761
-125
No files matched your search
@@ -31,7 +31,6 @@ from homeassistant.const import (
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.exceptions import TemplateError
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
|
||||
@@ -531,9 +530,6 @@ class MqttCover(
|
||||
|
||||
async def async_set_cover_tilt_position(self, **kwargs):
|
||||
"""Move the cover tilt to a specific position."""
|
||||
if ATTR_TILT_POSITION not in kwargs:
|
||||
return
|
||||
|
||||
position = float(kwargs[ATTR_TILT_POSITION])
|
||||
|
||||
# The position needs to be between min and max
|
||||
@@ -550,36 +546,31 @@ class MqttCover(
|
||||
async def async_set_cover_position(self, **kwargs):
|
||||
"""Move the cover to a specific position."""
|
||||
set_position_template = self._config.get(CONF_SET_POSITION_TEMPLATE)
|
||||
if ATTR_POSITION in kwargs:
|
||||
position = kwargs[ATTR_POSITION]
|
||||
percentage_position = position
|
||||
if set_position_template is not None:
|
||||
try:
|
||||
position = set_position_template.async_render(**kwargs)
|
||||
except TemplateError as ex:
|
||||
_LOGGER.error(ex)
|
||||
self._state = None
|
||||
elif (
|
||||
self._config[CONF_POSITION_OPEN] != 100
|
||||
and self._config[CONF_POSITION_CLOSED] != 0
|
||||
):
|
||||
position = self.find_in_range_from_percent(position, COVER_PAYLOAD)
|
||||
position = kwargs[ATTR_POSITION]
|
||||
percentage_position = position
|
||||
if set_position_template is not None:
|
||||
position = set_position_template.async_render(**kwargs)
|
||||
elif (
|
||||
self._config[CONF_POSITION_OPEN] != 100
|
||||
and self._config[CONF_POSITION_CLOSED] != 0
|
||||
):
|
||||
position = self.find_in_range_from_percent(position, COVER_PAYLOAD)
|
||||
|
||||
mqtt.async_publish(
|
||||
self.hass,
|
||||
self._config.get(CONF_SET_POSITION_TOPIC),
|
||||
position,
|
||||
self._config[CONF_QOS],
|
||||
self._config[CONF_RETAIN],
|
||||
mqtt.async_publish(
|
||||
self.hass,
|
||||
self._config.get(CONF_SET_POSITION_TOPIC),
|
||||
position,
|
||||
self._config[CONF_QOS],
|
||||
self._config[CONF_RETAIN],
|
||||
)
|
||||
if self._optimistic:
|
||||
self._state = (
|
||||
STATE_CLOSED
|
||||
if percentage_position == self._config[CONF_POSITION_CLOSED]
|
||||
else STATE_OPEN
|
||||
)
|
||||
if self._optimistic:
|
||||
self._state = (
|
||||
STATE_CLOSED
|
||||
if percentage_position == self._config[CONF_POSITION_CLOSED]
|
||||
else STATE_OPEN
|
||||
)
|
||||
self._position = percentage_position
|
||||
self.async_write_ha_state()
|
||||
self._position = percentage_position
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_toggle_tilt(self, **kwargs):
|
||||
"""Toggle the entity."""
|
||||
|
||||
@@ -6,7 +6,6 @@ import re
|
||||
|
||||
from homeassistant.components import mqtt
|
||||
from homeassistant.const import CONF_DEVICE, CONF_PLATFORM
|
||||
from homeassistant.helpers.discovery import async_load_platform
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
|
||||
@@ -35,21 +34,6 @@ SUPPORTED_COMPONENTS = [
|
||||
"vacuum",
|
||||
]
|
||||
|
||||
CONFIG_ENTRY_COMPONENTS = [
|
||||
"alarm_control_panel",
|
||||
"binary_sensor",
|
||||
"camera",
|
||||
"climate",
|
||||
"cover",
|
||||
"device_automation",
|
||||
"fan",
|
||||
"light",
|
||||
"lock",
|
||||
"sensor",
|
||||
"switch",
|
||||
"vacuum",
|
||||
]
|
||||
|
||||
ALREADY_DISCOVERED = "mqtt_discovered_components"
|
||||
DATA_CONFIG_ENTRY_LOCK = "mqtt_config_entry_lock"
|
||||
CONFIG_ENTRY_IS_SETUP = "mqtt_config_entry_is_setup"
|
||||
@@ -159,10 +143,6 @@ async def async_start(
|
||||
_LOGGER.info("Found new component: %s %s", component, discovery_id)
|
||||
hass.data[ALREADY_DISCOVERED][discovery_hash] = None
|
||||
|
||||
if component not in CONFIG_ENTRY_COMPONENTS:
|
||||
await async_load_platform(hass, component, "mqtt", payload, hass_config)
|
||||
return
|
||||
|
||||
config_entries_key = f"{component}.mqtt"
|
||||
async with hass.data[DATA_CONFIG_ENTRY_LOCK]:
|
||||
if config_entries_key not in hass.data[CONFIG_ENTRY_IS_SETUP]:
|
||||
|
||||
@@ -401,9 +401,6 @@ class MqttFan(
|
||||
|
||||
This method is a coroutine.
|
||||
"""
|
||||
if self._topic[CONF_SPEED_COMMAND_TOPIC] is None:
|
||||
return
|
||||
|
||||
if speed == SPEED_LOW:
|
||||
mqtt_payload = self._payload["SPEED_LOW"]
|
||||
elif speed == SPEED_MEDIUM:
|
||||
@@ -432,9 +429,6 @@ class MqttFan(
|
||||
|
||||
This method is a coroutine.
|
||||
"""
|
||||
if self._topic[CONF_OSCILLATION_COMMAND_TOPIC] is None:
|
||||
return
|
||||
|
||||
if oscillating is False:
|
||||
payload = self._payload["OSCILLATE_OFF_PAYLOAD"]
|
||||
else:
|
||||
|
||||
@@ -410,24 +410,26 @@ class MqttVacuum(
|
||||
|
||||
@property
|
||||
def fan_speed_list(self):
|
||||
"""Return the status of the vacuum."""
|
||||
if self.supported_features & SUPPORT_FAN_SPEED == 0:
|
||||
return []
|
||||
"""Return the status of the vacuum.
|
||||
|
||||
No need to check SUPPORT_FAN_SPEED, this won't be called if fan_speed is None.
|
||||
"""
|
||||
return self._fan_speed_list
|
||||
|
||||
@property
|
||||
def battery_level(self):
|
||||
"""Return the status of the vacuum."""
|
||||
if self.supported_features & SUPPORT_BATTERY == 0:
|
||||
return
|
||||
return None
|
||||
|
||||
return max(0, min(100, self._battery_level))
|
||||
|
||||
@property
|
||||
def battery_icon(self):
|
||||
"""Return the battery icon for the vacuum cleaner."""
|
||||
if self.supported_features & SUPPORT_BATTERY == 0:
|
||||
return
|
||||
"""Return the battery icon for the vacuum cleaner.
|
||||
|
||||
No need to check SUPPORT_BATTERY, this won't be called if battery_level is None.
|
||||
"""
|
||||
|
||||
return icon_for_battery_level(
|
||||
battery_level=self.battery_level, charging=self._charging
|
||||
|
||||
@@ -282,9 +282,10 @@ class MqttStateVacuum(
|
||||
|
||||
@property
|
||||
def fan_speed_list(self):
|
||||
"""Return fan speed list of the vacuum."""
|
||||
if self.supported_features & SUPPORT_FAN_SPEED == 0:
|
||||
return None
|
||||
"""Return fan speed list of the vacuum.
|
||||
|
||||
No need to check SUPPORT_FAN_SPEED, this won't be called if fan_speed is None.
|
||||
"""
|
||||
return self._fan_speed_list
|
||||
|
||||
@property
|
||||
|
||||
Reference in new issue
Block a user