Replace lists with tuples (2) (#53685)
This commit is contained in:
parent
5eba3e485b
commit
0815eede4b
61 changed files with 137 additions and 139 deletions
|
@ -61,7 +61,7 @@ class AcmedaCover(AcmedaBase, CoverEntity):
|
||||||
None is unknown, 0 is closed, 100 is fully open.
|
None is unknown, 0 is closed, 100 is fully open.
|
||||||
"""
|
"""
|
||||||
position = None
|
position = None
|
||||||
if self.roller.type in [7, 10]:
|
if self.roller.type in (7, 10):
|
||||||
position = 100 - self.roller.closed_percent
|
position = 100 - self.roller.closed_percent
|
||||||
return position
|
return position
|
||||||
|
|
||||||
|
|
|
@ -156,10 +156,10 @@ async def async_setup_entry(
|
||||||
coordinator = hass.data[DOMAIN][DATA_COORDINATOR][config_entry.entry_id]
|
coordinator = hass.data[DOMAIN][DATA_COORDINATOR][config_entry.entry_id]
|
||||||
|
|
||||||
sensors: list[AirVisualGeographySensor | AirVisualNodeProSensor]
|
sensors: list[AirVisualGeographySensor | AirVisualNodeProSensor]
|
||||||
if config_entry.data[CONF_INTEGRATION_TYPE] in [
|
if config_entry.data[CONF_INTEGRATION_TYPE] in (
|
||||||
INTEGRATION_TYPE_GEOGRAPHY_COORDS,
|
INTEGRATION_TYPE_GEOGRAPHY_COORDS,
|
||||||
INTEGRATION_TYPE_GEOGRAPHY_NAME,
|
INTEGRATION_TYPE_GEOGRAPHY_NAME,
|
||||||
]:
|
):
|
||||||
sensors = [
|
sensors = [
|
||||||
AirVisualGeographySensor(
|
AirVisualGeographySensor(
|
||||||
coordinator,
|
coordinator,
|
||||||
|
|
|
@ -456,7 +456,7 @@ class ADBDevice(MediaPlayerEntity):
|
||||||
|
|
||||||
async def async_get_media_image(self):
|
async def async_get_media_image(self):
|
||||||
"""Fetch current playing image."""
|
"""Fetch current playing image."""
|
||||||
if not self._screencap or self.state in [STATE_OFF, None] or not self.available:
|
if not self._screencap or self.state in (STATE_OFF, None) or not self.available:
|
||||||
return None, None
|
return None, None
|
||||||
self._attr_media_image_hash = (
|
self._attr_media_image_hash = (
|
||||||
f"{datetime.now().timestamp()}" if self._screencap else None
|
f"{datetime.now().timestamp()}" if self._screencap else None
|
||||||
|
|
|
@ -37,18 +37,18 @@ class AtagSensor(AtagEntity, SensorEntity):
|
||||||
"""Initialize Atag sensor."""
|
"""Initialize Atag sensor."""
|
||||||
super().__init__(coordinator, SENSORS[sensor])
|
super().__init__(coordinator, SENSORS[sensor])
|
||||||
self._attr_name = sensor
|
self._attr_name = sensor
|
||||||
if coordinator.data.report[self._id].sensorclass in [
|
if coordinator.data.report[self._id].sensorclass in (
|
||||||
DEVICE_CLASS_PRESSURE,
|
DEVICE_CLASS_PRESSURE,
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
DEVICE_CLASS_TEMPERATURE,
|
||||||
]:
|
):
|
||||||
self._attr_device_class = coordinator.data.report[self._id].sensorclass
|
self._attr_device_class = coordinator.data.report[self._id].sensorclass
|
||||||
if coordinator.data.report[self._id].measure in [
|
if coordinator.data.report[self._id].measure in (
|
||||||
PRESSURE_BAR,
|
PRESSURE_BAR,
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
TEMP_FAHRENHEIT,
|
TEMP_FAHRENHEIT,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
TIME_HOURS,
|
TIME_HOURS,
|
||||||
]:
|
):
|
||||||
self._attr_unit_of_measurement = coordinator.data.report[self._id].measure
|
self._attr_unit_of_measurement = coordinator.data.report[self._id].measure
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -248,10 +248,10 @@ class LoginFlowResourceView(HomeAssistantView):
|
||||||
if result["type"] != data_entry_flow.RESULT_TYPE_CREATE_ENTRY:
|
if result["type"] != data_entry_flow.RESULT_TYPE_CREATE_ENTRY:
|
||||||
# @log_invalid_auth does not work here since it returns HTTP 200
|
# @log_invalid_auth does not work here since it returns HTTP 200
|
||||||
# need manually log failed login attempts
|
# need manually log failed login attempts
|
||||||
if result.get("errors") is not None and result["errors"].get("base") in [
|
if result.get("errors") is not None and result["errors"].get("base") in (
|
||||||
"invalid_auth",
|
"invalid_auth",
|
||||||
"invalid_code",
|
"invalid_code",
|
||||||
]:
|
):
|
||||||
await process_wrong_login(request)
|
await process_wrong_login(request)
|
||||||
return self.json(_prepare_result_json(result))
|
return self.json(_prepare_result_json(result))
|
||||||
|
|
||||||
|
|
|
@ -255,7 +255,7 @@ class ChannelsPlayer(MediaPlayerEntity):
|
||||||
if media_type == MEDIA_TYPE_CHANNEL:
|
if media_type == MEDIA_TYPE_CHANNEL:
|
||||||
response = self.client.play_channel(media_id)
|
response = self.client.play_channel(media_id)
|
||||||
self.update_state(response)
|
self.update_state(response)
|
||||||
elif media_type in [MEDIA_TYPE_MOVIE, MEDIA_TYPE_EPISODE, MEDIA_TYPE_TVSHOW]:
|
elif media_type in (MEDIA_TYPE_MOVIE, MEDIA_TYPE_EPISODE, MEDIA_TYPE_TVSHOW):
|
||||||
response = self.client.play_recording(media_id)
|
response = self.client.play_recording(media_id)
|
||||||
self.update_state(response)
|
self.update_state(response)
|
||||||
|
|
||||||
|
|
|
@ -136,8 +136,8 @@ class DerivativeSensor(RestoreEntity, SensorEntity):
|
||||||
new_state = event.data.get("new_state")
|
new_state = event.data.get("new_state")
|
||||||
if (
|
if (
|
||||||
old_state is None
|
old_state is None
|
||||||
or old_state.state in [STATE_UNKNOWN, STATE_UNAVAILABLE]
|
or old_state.state in (STATE_UNKNOWN, STATE_UNAVAILABLE)
|
||||||
or new_state.state in [STATE_UNKNOWN, STATE_UNAVAILABLE]
|
or new_state.state in (STATE_UNKNOWN, STATE_UNAVAILABLE)
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -31,11 +31,11 @@ async def async_setup_entry(
|
||||||
for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"]:
|
for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"]:
|
||||||
for device in gateway.multi_level_switch_devices:
|
for device in gateway.multi_level_switch_devices:
|
||||||
for multi_level_switch in device.multi_level_switch_property:
|
for multi_level_switch in device.multi_level_switch_property:
|
||||||
if device.device_model_uid in [
|
if device.device_model_uid in (
|
||||||
"devolo.model.Thermostat:Valve",
|
"devolo.model.Thermostat:Valve",
|
||||||
"devolo.model.Room:Thermostat",
|
"devolo.model.Room:Thermostat",
|
||||||
"devolo.model.Eurotronic:Spirit:Device",
|
"devolo.model.Eurotronic:Spirit:Device",
|
||||||
]:
|
):
|
||||||
entities.append(
|
entities.append(
|
||||||
DevoloClimateDeviceEntity(
|
DevoloClimateDeviceEntity(
|
||||||
homecontrol=gateway,
|
homecontrol=gateway,
|
||||||
|
|
|
@ -21,7 +21,7 @@ _LOGGER: Final = logging.getLogger(__name__)
|
||||||
def host_valid(host: str) -> bool:
|
def host_valid(host: str) -> bool:
|
||||||
"""Return True if hostname or IP address is valid."""
|
"""Return True if hostname or IP address is valid."""
|
||||||
try:
|
try:
|
||||||
if ipaddress.ip_address(host).version in [4, 6]:
|
if ipaddress.ip_address(host).version in (4, 6):
|
||||||
return True
|
return True
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -109,11 +109,11 @@ class EcobeeSensor(SensorEntity):
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
if self._state in [
|
if self._state in (
|
||||||
ECOBEE_STATE_CALIBRATING,
|
ECOBEE_STATE_CALIBRATING,
|
||||||
ECOBEE_STATE_UNKNOWN,
|
ECOBEE_STATE_UNKNOWN,
|
||||||
"unknown",
|
"unknown",
|
||||||
]:
|
):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if self.type == "temperature":
|
if self.type == "temperature":
|
||||||
|
|
|
@ -137,10 +137,10 @@ class ECSensor(SensorEntity):
|
||||||
else:
|
else:
|
||||||
self._state = value
|
self._state = value
|
||||||
|
|
||||||
if sensor_data.get("unit") == "C" or self.sensor_type in [
|
if sensor_data.get("unit") == "C" or self.sensor_type in (
|
||||||
"wind_chill",
|
"wind_chill",
|
||||||
"humidex",
|
"humidex",
|
||||||
]:
|
):
|
||||||
self._unit = TEMP_CELSIUS
|
self._unit = TEMP_CELSIUS
|
||||||
self._device_class = DEVICE_CLASS_TEMPERATURE
|
self._device_class = DEVICE_CLASS_TEMPERATURE
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -111,10 +111,10 @@ class EsphomeFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||||
for entry in self._async_current_entries():
|
for entry in self._async_current_entries():
|
||||||
already_configured = False
|
already_configured = False
|
||||||
|
|
||||||
if CONF_HOST in entry.data and entry.data[CONF_HOST] in [
|
if CONF_HOST in entry.data and entry.data[CONF_HOST] in (
|
||||||
address,
|
address,
|
||||||
discovery_info[CONF_HOST],
|
discovery_info[CONF_HOST],
|
||||||
]:
|
):
|
||||||
# Is this address or IP address already configured?
|
# Is this address or IP address already configured?
|
||||||
already_configured = True
|
already_configured = True
|
||||||
elif DomainData.get(self.hass).is_entry_loaded(entry):
|
elif DomainData.get(self.hass).is_entry_loaded(entry):
|
||||||
|
|
|
@ -531,7 +531,7 @@ class EvoDevice(Entity):
|
||||||
return
|
return
|
||||||
if payload["unique_id"] != self._unique_id:
|
if payload["unique_id"] != self._unique_id:
|
||||||
return
|
return
|
||||||
if payload["service"] in [SVC_SET_ZONE_OVERRIDE, SVC_RESET_ZONE_OVERRIDE]:
|
if payload["service"] in (SVC_SET_ZONE_OVERRIDE, SVC_RESET_ZONE_OVERRIDE):
|
||||||
await self.async_zone_svc_request(payload["service"], payload["data"])
|
await self.async_zone_svc_request(payload["service"], payload["data"])
|
||||||
return
|
return
|
||||||
await self.async_tcs_svc_request(payload["service"], payload["data"])
|
await self.async_tcs_svc_request(payload["service"], payload["data"])
|
||||||
|
|
|
@ -194,7 +194,7 @@ class EvoZone(EvoChild, EvoClimateEntity):
|
||||||
@property
|
@property
|
||||||
def hvac_mode(self) -> str:
|
def hvac_mode(self) -> str:
|
||||||
"""Return the current operating mode of a Zone."""
|
"""Return the current operating mode of a Zone."""
|
||||||
if self._evo_tcs.systemModeStatus["mode"] in [EVO_AWAY, EVO_HEATOFF]:
|
if self._evo_tcs.systemModeStatus["mode"] in (EVO_AWAY, EVO_HEATOFF):
|
||||||
return HVAC_MODE_AUTO
|
return HVAC_MODE_AUTO
|
||||||
is_off = self.target_temperature <= self.min_temp
|
is_off = self.target_temperature <= self.min_temp
|
||||||
return HVAC_MODE_OFF if is_off else HVAC_MODE_HEAT
|
return HVAC_MODE_OFF if is_off else HVAC_MODE_HEAT
|
||||||
|
@ -207,7 +207,7 @@ class EvoZone(EvoChild, EvoClimateEntity):
|
||||||
@property
|
@property
|
||||||
def preset_mode(self) -> str | None:
|
def preset_mode(self) -> str | None:
|
||||||
"""Return the current preset mode, e.g., home, away, temp."""
|
"""Return the current preset mode, e.g., home, away, temp."""
|
||||||
if self._evo_tcs.systemModeStatus["mode"] in [EVO_AWAY, EVO_HEATOFF]:
|
if self._evo_tcs.systemModeStatus["mode"] in (EVO_AWAY, EVO_HEATOFF):
|
||||||
return TCS_PRESET_TO_HA.get(self._evo_tcs.systemModeStatus["mode"])
|
return TCS_PRESET_TO_HA.get(self._evo_tcs.systemModeStatus["mode"])
|
||||||
return EVO_PRESET_TO_HA.get(self._evo_device.setpointStatus["setpointMode"])
|
return EVO_PRESET_TO_HA.get(self._evo_device.setpointStatus["setpointMode"])
|
||||||
|
|
||||||
|
|
|
@ -209,7 +209,7 @@ class SensorFilter(SensorEntity):
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
return
|
return
|
||||||
|
|
||||||
if new_state.state in [STATE_UNKNOWN, STATE_UNAVAILABLE]:
|
if new_state.state in (STATE_UNKNOWN, STATE_UNAVAILABLE):
|
||||||
self._state = new_state.state
|
self._state = new_state.state
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
return
|
return
|
||||||
|
|
|
@ -152,8 +152,8 @@ class IntegrationSensor(RestoreEntity, SensorEntity):
|
||||||
new_state = event.data.get("new_state")
|
new_state = event.data.get("new_state")
|
||||||
if (
|
if (
|
||||||
old_state is None
|
old_state is None
|
||||||
or old_state.state in [STATE_UNKNOWN, STATE_UNAVAILABLE]
|
or old_state.state in (STATE_UNKNOWN, STATE_UNAVAILABLE)
|
||||||
or new_state.state in [STATE_UNKNOWN, STATE_UNAVAILABLE]
|
or new_state.state in (STATE_UNKNOWN, STATE_UNAVAILABLE)
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -397,7 +397,7 @@ class ISYBinarySensorHeartbeat(ISYNodeEntity, BinarySensorEntity):
|
||||||
|
|
||||||
The ISY uses both DON and DOF commands (alternating) for a heartbeat.
|
The ISY uses both DON and DOF commands (alternating) for a heartbeat.
|
||||||
"""
|
"""
|
||||||
if event.control in [CMD_ON, CMD_OFF]:
|
if event.control in (CMD_ON, CMD_OFF):
|
||||||
self.async_heartbeat()
|
self.async_heartbeat()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
|
|
@ -114,10 +114,10 @@ def _check_for_insteon_type(
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Thermostats, which has a "Heat" and "Cool" sub-node on address 2 and 3
|
# Thermostats, which has a "Heat" and "Cool" sub-node on address 2 and 3
|
||||||
if platform == CLIMATE and subnode_id in [
|
if platform == CLIMATE and subnode_id in (
|
||||||
SUBNODE_CLIMATE_COOL,
|
SUBNODE_CLIMATE_COOL,
|
||||||
SUBNODE_CLIMATE_HEAT,
|
SUBNODE_CLIMATE_HEAT,
|
||||||
]:
|
):
|
||||||
hass_isy_data[ISY994_NODES][BINARY_SENSOR].append(node)
|
hass_isy_data[ISY994_NODES][BINARY_SENSOR].append(node)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ def _check_for_uom_id(
|
||||||
This is used for versions of the ISY firmware that report uoms as a single
|
This is used for versions of the ISY firmware that report uoms as a single
|
||||||
ID. We can often infer what type of device it is by that ID.
|
ID. We can often infer what type of device it is by that ID.
|
||||||
"""
|
"""
|
||||||
if not hasattr(node, "uom") or node.uom in [None, ""]:
|
if not hasattr(node, "uom") or node.uom in (None, ""):
|
||||||
# Node doesn't have a uom (Scenes for example)
|
# Node doesn't have a uom (Scenes for example)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ def _check_for_states_in_uom(
|
||||||
possible "human readable" states. This filter passes if all of the possible
|
possible "human readable" states. This filter passes if all of the possible
|
||||||
states fit inside the given filter.
|
states fit inside the given filter.
|
||||||
"""
|
"""
|
||||||
if not hasattr(node, "uom") or node.uom in [None, ""]:
|
if not hasattr(node, "uom") or node.uom in (None, ""):
|
||||||
# Node doesn't have a uom (Scenes for example)
|
# Node doesn't have a uom (Scenes for example)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -413,7 +413,7 @@ def convert_isy_value_to_hass(
|
||||||
"""
|
"""
|
||||||
if value is None or value == ISY_VALUE_UNKNOWN:
|
if value is None or value == ISY_VALUE_UNKNOWN:
|
||||||
return None
|
return None
|
||||||
if uom in [UOM_DOUBLE_TEMP, UOM_ISYV4_DEGREES]:
|
if uom in (UOM_DOUBLE_TEMP, UOM_ISYV4_DEGREES):
|
||||||
return round(float(value) / 2.0, 1)
|
return round(float(value) / 2.0, 1)
|
||||||
if precision not in ("0", 0):
|
if precision not in ("0", 0):
|
||||||
return round(float(value) / 10 ** int(precision), int(precision))
|
return round(float(value) / 10 ** int(precision), int(precision))
|
||||||
|
|
|
@ -61,7 +61,7 @@ class ISYSensorEntity(ISYNodeEntity, SensorEntity):
|
||||||
if isy_states:
|
if isy_states:
|
||||||
return isy_states
|
return isy_states
|
||||||
|
|
||||||
if uom in [UOM_ON_OFF, UOM_INDEX]:
|
if uom in (UOM_ON_OFF, UOM_INDEX):
|
||||||
return uom
|
return uom
|
||||||
|
|
||||||
return UOM_FRIENDLY_NAME.get(uom)
|
return UOM_FRIENDLY_NAME.get(uom)
|
||||||
|
@ -80,7 +80,7 @@ class ISYSensorEntity(ISYNodeEntity, SensorEntity):
|
||||||
if isinstance(uom, dict):
|
if isinstance(uom, dict):
|
||||||
return uom.get(value, value)
|
return uom.get(value, value)
|
||||||
|
|
||||||
if uom in [UOM_INDEX, UOM_ON_OFF]:
|
if uom in (UOM_INDEX, UOM_ON_OFF):
|
||||||
return self._node.formatted
|
return self._node.formatted
|
||||||
|
|
||||||
# Check if this is an index type and get formatted value
|
# Check if this is an index type and get formatted value
|
||||||
|
@ -101,7 +101,7 @@ class ISYSensorEntity(ISYNodeEntity, SensorEntity):
|
||||||
"""Get the Home Assistant unit of measurement for the device."""
|
"""Get the Home Assistant unit of measurement for the device."""
|
||||||
raw_units = self.raw_unit_of_measurement
|
raw_units = self.raw_unit_of_measurement
|
||||||
# Check if this is a known index pair UOM
|
# Check if this is a known index pair UOM
|
||||||
if isinstance(raw_units, dict) or raw_units in [UOM_ON_OFF, UOM_INDEX]:
|
if isinstance(raw_units, dict) or raw_units in (UOM_ON_OFF, UOM_INDEX):
|
||||||
return None
|
return None
|
||||||
if raw_units in (TEMP_FAHRENHEIT, TEMP_CELSIUS, UOM_DOUBLE_TEMP):
|
if raw_units in (TEMP_FAHRENHEIT, TEMP_CELSIUS, UOM_DOUBLE_TEMP):
|
||||||
return self.hass.config.units.temperature_unit
|
return self.hass.config.units.temperature_unit
|
||||||
|
|
|
@ -79,9 +79,9 @@ def get_device_connection(
|
||||||
|
|
||||||
def get_resource(domain_name: str, domain_data: ConfigType) -> str:
|
def get_resource(domain_name: str, domain_data: ConfigType) -> str:
|
||||||
"""Return the resource for the specified domain_data."""
|
"""Return the resource for the specified domain_data."""
|
||||||
if domain_name in ["switch", "light"]:
|
if domain_name in ("switch", "light"):
|
||||||
return cast(str, domain_data["output"])
|
return cast(str, domain_data["output"])
|
||||||
if domain_name in ["binary_sensor", "sensor"]:
|
if domain_name in ("binary_sensor", "sensor"):
|
||||||
return cast(str, domain_data["source"])
|
return cast(str, domain_data["source"])
|
||||||
if domain_name == "cover":
|
if domain_name == "cover":
|
||||||
return cast(str, domain_data["motor"])
|
return cast(str, domain_data["motor"])
|
||||||
|
|
|
@ -119,7 +119,7 @@ class MaxCubeClimate(ClimateEntity):
|
||||||
def hvac_mode(self):
|
def hvac_mode(self):
|
||||||
"""Return current operation mode."""
|
"""Return current operation mode."""
|
||||||
mode = self._device.mode
|
mode = self._device.mode
|
||||||
if mode in [MAX_DEVICE_MODE_AUTOMATIC, MAX_DEVICE_MODE_BOOST]:
|
if mode in (MAX_DEVICE_MODE_AUTOMATIC, MAX_DEVICE_MODE_BOOST):
|
||||||
return HVAC_MODE_AUTO
|
return HVAC_MODE_AUTO
|
||||||
if (
|
if (
|
||||||
mode == MAX_DEVICE_MODE_MANUAL
|
mode == MAX_DEVICE_MODE_MANUAL
|
||||||
|
|
|
@ -817,7 +817,7 @@ class MediaPlayerEntity(Entity):
|
||||||
await self.hass.async_add_executor_job(self.toggle)
|
await self.hass.async_add_executor_job(self.toggle)
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.state in [STATE_OFF, STATE_IDLE]:
|
if self.state in (STATE_OFF, STATE_IDLE):
|
||||||
await self.async_turn_on()
|
await self.async_turn_on()
|
||||||
else:
|
else:
|
||||||
await self.async_turn_off()
|
await self.async_turn_off()
|
||||||
|
|
|
@ -63,12 +63,12 @@ async def _async_reproduce_states(
|
||||||
# entities that are off have no other attributes to restore
|
# entities that are off have no other attributes to restore
|
||||||
return
|
return
|
||||||
|
|
||||||
if state.state in [
|
if state.state in (
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
STATE_PLAYING,
|
STATE_PLAYING,
|
||||||
STATE_IDLE,
|
STATE_IDLE,
|
||||||
STATE_PAUSED,
|
STATE_PAUSED,
|
||||||
]:
|
):
|
||||||
await call_service(SERVICE_TURN_ON, [])
|
await call_service(SERVICE_TURN_ON, [])
|
||||||
|
|
||||||
if ATTR_MEDIA_VOLUME_LEVEL in state.attributes:
|
if ATTR_MEDIA_VOLUME_LEVEL in state.attributes:
|
||||||
|
|
|
@ -56,7 +56,7 @@ async def async_setup_entry(
|
||||||
if coordinator_alert:
|
if coordinator_alert:
|
||||||
entities.append(MeteoFranceAlertSensor(sensor_type, coordinator_alert))
|
entities.append(MeteoFranceAlertSensor(sensor_type, coordinator_alert))
|
||||||
|
|
||||||
elif sensor_type in ["rain_chance", "freeze_chance", "snow_chance"]:
|
elif sensor_type in ("rain_chance", "freeze_chance", "snow_chance"):
|
||||||
if coordinator_forecast.data.probability_forecast:
|
if coordinator_forecast.data.probability_forecast:
|
||||||
entities.append(MeteoFranceSensor(sensor_type, coordinator_forecast))
|
entities.append(MeteoFranceSensor(sensor_type, coordinator_forecast))
|
||||||
else:
|
else:
|
||||||
|
@ -129,7 +129,7 @@ class MeteoFranceSensor(CoordinatorEntity, SensorEntity):
|
||||||
else:
|
else:
|
||||||
value = data[path[1]]
|
value = data[path[1]]
|
||||||
|
|
||||||
if self._type in ["wind_speed", "wind_gust"]:
|
if self._type in ("wind_speed", "wind_gust"):
|
||||||
# convert API wind speed from m/s to km/h
|
# convert API wind speed from m/s to km/h
|
||||||
value = round(value * 3.6)
|
value = round(value * 3.6)
|
||||||
return value
|
return value
|
||||||
|
|
|
@ -153,7 +153,7 @@ class MobileAppNotificationService(BaseNotificationService):
|
||||||
)
|
)
|
||||||
result = await response.json()
|
result = await response.json()
|
||||||
|
|
||||||
if response.status in [HTTP_OK, HTTP_CREATED, HTTP_ACCEPTED]:
|
if response.status in (HTTP_OK, HTTP_CREATED, HTTP_ACCEPTED):
|
||||||
log_rate_limits(self.hass, entry_data[ATTR_DEVICE_NAME], result)
|
log_rate_limits(self.hass, entry_data[ATTR_DEVICE_NAME], result)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ class BaseStructPlatform(BasePlatform, RestoreEntity):
|
||||||
|
|
||||||
def _swap_registers(self, registers):
|
def _swap_registers(self, registers):
|
||||||
"""Do swap as needed."""
|
"""Do swap as needed."""
|
||||||
if self._swap in [CONF_SWAP_BYTE, CONF_SWAP_WORD_BYTE]:
|
if self._swap in (CONF_SWAP_BYTE, CONF_SWAP_WORD_BYTE):
|
||||||
# convert [12][34] --> [21][43]
|
# convert [12][34] --> [21][43]
|
||||||
for i, register in enumerate(registers):
|
for i, register in enumerate(registers):
|
||||||
registers[i] = int.from_bytes(
|
registers[i] = int.from_bytes(
|
||||||
|
@ -109,7 +109,7 @@ class BaseStructPlatform(BasePlatform, RestoreEntity):
|
||||||
byteorder="big",
|
byteorder="big",
|
||||||
signed=False,
|
signed=False,
|
||||||
)
|
)
|
||||||
if self._swap in [CONF_SWAP_WORD, CONF_SWAP_WORD_BYTE]:
|
if self._swap in (CONF_SWAP_WORD, CONF_SWAP_WORD_BYTE):
|
||||||
# convert [12][34] ==> [34][12]
|
# convert [12][34] ==> [34][12]
|
||||||
registers.reverse()
|
registers.reverse()
|
||||||
return registers
|
return registers
|
||||||
|
|
|
@ -114,14 +114,14 @@ class ModbusThermostat(BaseStructPlatform, RestoreEntity, ClimateEntity):
|
||||||
target_temperature = (
|
target_temperature = (
|
||||||
float(kwargs.get(ATTR_TEMPERATURE)) - self._offset
|
float(kwargs.get(ATTR_TEMPERATURE)) - self._offset
|
||||||
) / self._scale
|
) / self._scale
|
||||||
if self._data_type in [
|
if self._data_type in (
|
||||||
DATA_TYPE_INT16,
|
DATA_TYPE_INT16,
|
||||||
DATA_TYPE_INT32,
|
DATA_TYPE_INT32,
|
||||||
DATA_TYPE_INT64,
|
DATA_TYPE_INT64,
|
||||||
DATA_TYPE_UINT16,
|
DATA_TYPE_UINT16,
|
||||||
DATA_TYPE_UINT32,
|
DATA_TYPE_UINT32,
|
||||||
DATA_TYPE_UINT64,
|
DATA_TYPE_UINT64,
|
||||||
]:
|
):
|
||||||
target_temperature = int(target_temperature)
|
target_temperature = int(target_temperature)
|
||||||
as_bytes = struct.pack(self._structure, target_temperature)
|
as_bytes = struct.pack(self._structure, target_temperature)
|
||||||
raw_regs = [
|
raw_regs = [
|
||||||
|
|
|
@ -67,7 +67,7 @@ def struct_validator(config):
|
||||||
name = config[CONF_NAME]
|
name = config[CONF_NAME]
|
||||||
structure = config.get(CONF_STRUCTURE)
|
structure = config.get(CONF_STRUCTURE)
|
||||||
swap_type = config.get(CONF_SWAP)
|
swap_type = config.get(CONF_SWAP)
|
||||||
if data_type in [DATA_TYPE_INT, DATA_TYPE_UINT, DATA_TYPE_FLOAT]:
|
if data_type in (DATA_TYPE_INT, DATA_TYPE_UINT, DATA_TYPE_FLOAT):
|
||||||
error = f"{name} with {data_type} is not valid, trying to convert"
|
error = f"{name} with {data_type} is not valid, trying to convert"
|
||||||
_LOGGER.warning(error)
|
_LOGGER.warning(error)
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -126,10 +126,10 @@ class MotionEyeMjpegCamera(MotionEyeEntity, MjpegCamera):
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""Convert a motionEye camera to MjpegCamera internal properties."""
|
"""Convert a motionEye camera to MjpegCamera internal properties."""
|
||||||
auth = None
|
auth = None
|
||||||
if camera.get(KEY_STREAMING_AUTH_MODE) in [
|
if camera.get(KEY_STREAMING_AUTH_MODE) in (
|
||||||
HTTP_BASIC_AUTHENTICATION,
|
HTTP_BASIC_AUTHENTICATION,
|
||||||
HTTP_DIGEST_AUTHENTICATION,
|
HTTP_DIGEST_AUTHENTICATION,
|
||||||
]:
|
):
|
||||||
auth = camera[KEY_STREAMING_AUTH_MODE]
|
auth = camera[KEY_STREAMING_AUTH_MODE]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -291,7 +291,7 @@ async def async_start( # noqa: C901
|
||||||
result
|
result
|
||||||
and result["type"] == RESULT_TYPE_ABORT
|
and result["type"] == RESULT_TYPE_ABORT
|
||||||
and result["reason"]
|
and result["reason"]
|
||||||
in ["already_configured", "single_instance_allowed"]
|
in ("already_configured", "single_instance_allowed")
|
||||||
):
|
):
|
||||||
unsub = hass.data[INTEGRATION_UNSUBSCRIBE].pop(key, None)
|
unsub = hass.data[INTEGRATION_UNSUBSCRIBE].pop(key, None)
|
||||||
if unsub is None:
|
if unsub is None:
|
||||||
|
|
|
@ -168,13 +168,13 @@ class NetatmoCamera(NetatmoBase, Camera):
|
||||||
return
|
return
|
||||||
|
|
||||||
if data["home_id"] == self._home_id and data["camera_id"] == self._id:
|
if data["home_id"] == self._home_id and data["camera_id"] == self._id:
|
||||||
if data[WEBHOOK_PUSH_TYPE] in ["NACamera-off", "NACamera-disconnection"]:
|
if data[WEBHOOK_PUSH_TYPE] in ("NACamera-off", "NACamera-disconnection"):
|
||||||
self.is_streaming = False
|
self.is_streaming = False
|
||||||
self._status = "off"
|
self._status = "off"
|
||||||
elif data[WEBHOOK_PUSH_TYPE] in [
|
elif data[WEBHOOK_PUSH_TYPE] in (
|
||||||
"NACamera-on",
|
"NACamera-on",
|
||||||
WEBHOOK_NACAMERA_CONNECTION,
|
WEBHOOK_NACAMERA_CONNECTION,
|
||||||
]:
|
):
|
||||||
self.is_streaming = True
|
self.is_streaming = True
|
||||||
self._status = "on"
|
self._status = "on"
|
||||||
elif data[WEBHOOK_PUSH_TYPE] == WEBHOOK_LIGHT_MODE:
|
elif data[WEBHOOK_PUSH_TYPE] == WEBHOOK_LIGHT_MODE:
|
||||||
|
|
|
@ -396,7 +396,7 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
||||||
)
|
)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
preset_mode in [PRESET_BOOST, STATE_NETATMO_MAX]
|
preset_mode in (PRESET_BOOST, STATE_NETATMO_MAX)
|
||||||
and self._model == NA_VALVE
|
and self._model == NA_VALVE
|
||||||
and self.hvac_mode == HVAC_MODE_HEAT
|
and self.hvac_mode == HVAC_MODE_HEAT
|
||||||
):
|
):
|
||||||
|
@ -405,7 +405,7 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
||||||
STATE_NETATMO_HOME,
|
STATE_NETATMO_HOME,
|
||||||
)
|
)
|
||||||
elif (
|
elif (
|
||||||
preset_mode in [PRESET_BOOST, STATE_NETATMO_MAX] and self._model == NA_VALVE
|
preset_mode in (PRESET_BOOST, STATE_NETATMO_MAX) and self._model == NA_VALVE
|
||||||
):
|
):
|
||||||
await self._home_status.async_set_room_thermpoint(
|
await self._home_status.async_set_room_thermpoint(
|
||||||
self._id,
|
self._id,
|
||||||
|
@ -413,17 +413,17 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
||||||
DEFAULT_MAX_TEMP,
|
DEFAULT_MAX_TEMP,
|
||||||
)
|
)
|
||||||
elif (
|
elif (
|
||||||
preset_mode in [PRESET_BOOST, STATE_NETATMO_MAX]
|
preset_mode in (PRESET_BOOST, STATE_NETATMO_MAX)
|
||||||
and self.hvac_mode == HVAC_MODE_HEAT
|
and self.hvac_mode == HVAC_MODE_HEAT
|
||||||
):
|
):
|
||||||
await self._home_status.async_set_room_thermpoint(
|
await self._home_status.async_set_room_thermpoint(
|
||||||
self._id, STATE_NETATMO_HOME
|
self._id, STATE_NETATMO_HOME
|
||||||
)
|
)
|
||||||
elif preset_mode in [PRESET_BOOST, STATE_NETATMO_MAX]:
|
elif preset_mode in (PRESET_BOOST, STATE_NETATMO_MAX):
|
||||||
await self._home_status.async_set_room_thermpoint(
|
await self._home_status.async_set_room_thermpoint(
|
||||||
self._id, PRESET_MAP_NETATMO[preset_mode]
|
self._id, PRESET_MAP_NETATMO[preset_mode]
|
||||||
)
|
)
|
||||||
elif preset_mode in [PRESET_SCHEDULE, PRESET_FROST_GUARD, PRESET_AWAY]:
|
elif preset_mode in (PRESET_SCHEDULE, PRESET_FROST_GUARD, PRESET_AWAY):
|
||||||
await self._home_status.async_set_thermmode(PRESET_MAP_NETATMO[preset_mode])
|
await self._home_status.async_set_thermmode(PRESET_MAP_NETATMO[preset_mode])
|
||||||
else:
|
else:
|
||||||
_LOGGER.error("Preset mode '%s' not available", preset_mode)
|
_LOGGER.error("Preset mode '%s' not available", preset_mode)
|
||||||
|
|
|
@ -150,7 +150,7 @@ async def async_setup_entry( # noqa: C901
|
||||||
# The actual removal action of a Z-Wave node is reported as instance event
|
# The actual removal action of a Z-Wave node is reported as instance event
|
||||||
# Only when this event is detected we cleanup the device and entities from hass
|
# Only when this event is detected we cleanup the device and entities from hass
|
||||||
# Note: Find a more elegant way of doing this, e.g. a notification of this event from OZW
|
# Note: Find a more elegant way of doing this, e.g. a notification of this event from OZW
|
||||||
if event in ["removenode", "removefailednode"] and "Node" in event_data:
|
if event in ("removenode", "removefailednode") and "Node" in event_data:
|
||||||
removed_nodes.append(event_data["Node"])
|
removed_nodes.append(event_data["Node"])
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -160,9 +160,7 @@ async def async_setup_entry( # noqa: C901
|
||||||
node_id = value.node.node_id
|
node_id = value.node.node_id
|
||||||
|
|
||||||
# Filter out CommandClasses we're definitely not interested in.
|
# Filter out CommandClasses we're definitely not interested in.
|
||||||
if value.command_class in [
|
if value.command_class in (CommandClass.MANUFACTURER_SPECIFIC,):
|
||||||
CommandClass.MANUFACTURER_SPECIFIC,
|
|
||||||
]:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
|
@ -213,10 +211,10 @@ async def async_setup_entry( # noqa: C901
|
||||||
value.command_class,
|
value.command_class,
|
||||||
)
|
)
|
||||||
# Handle a scene activation message
|
# Handle a scene activation message
|
||||||
if value.command_class in [
|
if value.command_class in (
|
||||||
CommandClass.SCENE_ACTIVATION,
|
CommandClass.SCENE_ACTIVATION,
|
||||||
CommandClass.CENTRAL_SCENE,
|
CommandClass.CENTRAL_SCENE,
|
||||||
]:
|
):
|
||||||
async_handle_scene_activated(hass, value)
|
async_handle_scene_activated(hass, value)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -88,11 +88,11 @@ class ZwaveSensorBase(ZWaveDeviceEntity, SensorEntity):
|
||||||
def entity_registry_enabled_default(self) -> bool:
|
def entity_registry_enabled_default(self) -> bool:
|
||||||
"""Return if the entity should be enabled when first added to the entity registry."""
|
"""Return if the entity should be enabled when first added to the entity registry."""
|
||||||
# We hide some of the more advanced sensors by default to not overwhelm users
|
# We hide some of the more advanced sensors by default to not overwhelm users
|
||||||
if self.values.primary.command_class in [
|
if self.values.primary.command_class in (
|
||||||
CommandClass.BASIC,
|
CommandClass.BASIC,
|
||||||
CommandClass.INDICATOR,
|
CommandClass.INDICATOR,
|
||||||
CommandClass.NOTIFICATION,
|
CommandClass.NOTIFICATION,
|
||||||
]:
|
):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -122,7 +122,7 @@ def _get_config_params(node, *args):
|
||||||
for param in raw_values:
|
for param in raw_values:
|
||||||
schema = {}
|
schema = {}
|
||||||
|
|
||||||
if param["type"] in ["Byte", "Int", "Short"]:
|
if param["type"] in ("Byte", "Int", "Short"):
|
||||||
schema = vol.Schema(
|
schema = vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required(param["label"], default=param["value"]): vol.All(
|
vol.Required(param["label"], default=param["value"]): vol.All(
|
||||||
|
|
|
@ -191,7 +191,7 @@ def browse_media( # noqa: C901
|
||||||
return BrowseMedia(**payload)
|
return BrowseMedia(**payload)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if media_content_type in ["server", None]:
|
if media_content_type in ("server", None):
|
||||||
return server_payload(entity.plex_server)
|
return server_payload(entity.plex_server)
|
||||||
|
|
||||||
if media_content_type == "library":
|
if media_content_type == "library":
|
||||||
|
|
|
@ -256,7 +256,7 @@ class PlexMediaPlayer(MediaPlayerEntity):
|
||||||
@property
|
@property
|
||||||
def _is_player_active(self):
|
def _is_player_active(self):
|
||||||
"""Report if the client is playing media."""
|
"""Report if the client is playing media."""
|
||||||
return self.state in [STATE_PLAYING, STATE_PAUSED]
|
return self.state in (STATE_PLAYING, STATE_PAUSED)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _active_media_plexapi_type(self):
|
def _active_media_plexapi_type(self):
|
||||||
|
|
|
@ -291,10 +291,10 @@ class PlexServer:
|
||||||
media = self.fetch_item(rating_key)
|
media = self.fetch_item(rating_key)
|
||||||
active_session.update_media(media)
|
active_session.update_media(media)
|
||||||
|
|
||||||
if active_session.media_content_id != rating_key and state in [
|
if active_session.media_content_id != rating_key and state in (
|
||||||
"playing",
|
"playing",
|
||||||
"paused",
|
"paused",
|
||||||
]:
|
):
|
||||||
await self.hass.async_add_executor_job(update_with_new_media)
|
await self.hass.async_add_executor_job(update_with_new_media)
|
||||||
|
|
||||||
async_dispatcher_send(
|
async_dispatcher_send(
|
||||||
|
|
|
@ -194,7 +194,7 @@ class RadarrSensor(SensorEntity):
|
||||||
return
|
return
|
||||||
|
|
||||||
if res.status_code == HTTP_OK:
|
if res.status_code == HTTP_OK:
|
||||||
if self.type in ["upcoming", "movies", "commands"]:
|
if self.type in ("upcoming", "movies", "commands"):
|
||||||
self.data = res.json()
|
self.data = res.json()
|
||||||
self._state = len(self.data)
|
self._state = len(self.data)
|
||||||
elif self.type == "diskspace":
|
elif self.type == "diskspace":
|
||||||
|
|
|
@ -357,7 +357,7 @@ class SensiboClimate(ClimateEntity):
|
||||||
if change_needed:
|
if change_needed:
|
||||||
await self._async_set_ac_state_property("on", state != HVAC_MODE_OFF, True)
|
await self._async_set_ac_state_property("on", state != HVAC_MODE_OFF, True)
|
||||||
|
|
||||||
if state in [STATE_ON, HVAC_MODE_OFF]:
|
if state in (STATE_ON, HVAC_MODE_OFF):
|
||||||
self._external_state = None
|
self._external_state = None
|
||||||
else:
|
else:
|
||||||
self._external_state = state
|
self._external_state = state
|
||||||
|
|
|
@ -268,7 +268,7 @@ class SmappeeSensor(SensorEntity):
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name for this sensor."""
|
"""Return the name for this sensor."""
|
||||||
if self._sensor in ["sensor", "load"]:
|
if self._sensor in ("sensor", "load"):
|
||||||
return (
|
return (
|
||||||
f"{self._service_location.service_location_name} - "
|
f"{self._service_location.service_location_name} - "
|
||||||
f"{self._sensor.title()} - {self._name}"
|
f"{self._sensor.title()} - {self._name}"
|
||||||
|
@ -301,7 +301,7 @@ class SmappeeSensor(SensorEntity):
|
||||||
self,
|
self,
|
||||||
):
|
):
|
||||||
"""Return the unique ID for this sensor."""
|
"""Return the unique ID for this sensor."""
|
||||||
if self._sensor in ["load", "sensor"]:
|
if self._sensor in ("load", "sensor"):
|
||||||
return (
|
return (
|
||||||
f"{self._service_location.device_serial_number}-"
|
f"{self._service_location.device_serial_number}-"
|
||||||
f"{self._service_location.service_location_id}-"
|
f"{self._service_location.service_location_id}-"
|
||||||
|
@ -337,11 +337,11 @@ class SmappeeSensor(SensorEntity):
|
||||||
self._state = self._service_location.solar_power
|
self._state = self._service_location.solar_power
|
||||||
elif self._sensor == "alwayson":
|
elif self._sensor == "alwayson":
|
||||||
self._state = self._service_location.alwayson
|
self._state = self._service_location.alwayson
|
||||||
elif self._sensor in [
|
elif self._sensor in (
|
||||||
"phase_voltages_a",
|
"phase_voltages_a",
|
||||||
"phase_voltages_b",
|
"phase_voltages_b",
|
||||||
"phase_voltages_c",
|
"phase_voltages_c",
|
||||||
]:
|
):
|
||||||
phase_voltages = self._service_location.phase_voltages
|
phase_voltages = self._service_location.phase_voltages
|
||||||
if phase_voltages is not None:
|
if phase_voltages is not None:
|
||||||
if self._sensor == "phase_voltages_a":
|
if self._sensor == "phase_voltages_a":
|
||||||
|
@ -350,7 +350,7 @@ class SmappeeSensor(SensorEntity):
|
||||||
self._state = phase_voltages[1]
|
self._state = phase_voltages[1]
|
||||||
elif self._sensor == "phase_voltages_c":
|
elif self._sensor == "phase_voltages_c":
|
||||||
self._state = phase_voltages[2]
|
self._state = phase_voltages[2]
|
||||||
elif self._sensor in ["line_voltages_a", "line_voltages_b", "line_voltages_c"]:
|
elif self._sensor in ("line_voltages_a", "line_voltages_b", "line_voltages_c"):
|
||||||
line_voltages = self._service_location.line_voltages
|
line_voltages = self._service_location.line_voltages
|
||||||
if line_voltages is not None:
|
if line_voltages is not None:
|
||||||
if self._sensor == "line_voltages_a":
|
if self._sensor == "line_voltages_a":
|
||||||
|
@ -359,14 +359,14 @@ class SmappeeSensor(SensorEntity):
|
||||||
self._state = line_voltages[1]
|
self._state = line_voltages[1]
|
||||||
elif self._sensor == "line_voltages_c":
|
elif self._sensor == "line_voltages_c":
|
||||||
self._state = line_voltages[2]
|
self._state = line_voltages[2]
|
||||||
elif self._sensor in [
|
elif self._sensor in (
|
||||||
"power_today",
|
"power_today",
|
||||||
"power_current_hour",
|
"power_current_hour",
|
||||||
"power_last_5_minutes",
|
"power_last_5_minutes",
|
||||||
"solar_today",
|
"solar_today",
|
||||||
"solar_current_hour",
|
"solar_current_hour",
|
||||||
"alwayson_today",
|
"alwayson_today",
|
||||||
]:
|
):
|
||||||
trend_value = self._service_location.aggregated_values.get(self._sensor)
|
trend_value = self._service_location.aggregated_values.get(self._sensor)
|
||||||
self._state = round(trend_value) if trend_value is not None else None
|
self._state = round(trend_value) if trend_value is not None else None
|
||||||
elif self._sensor == "load":
|
elif self._sensor == "load":
|
||||||
|
|
|
@ -14,7 +14,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
entities = []
|
entities = []
|
||||||
for service_location in smappee_base.smappee.service_locations.values():
|
for service_location in smappee_base.smappee.service_locations.values():
|
||||||
for actuator_id, actuator in service_location.actuators.items():
|
for actuator_id, actuator in service_location.actuators.items():
|
||||||
if actuator.type in ["SWITCH", "COMFORT_PLUG"]:
|
if actuator.type in ("SWITCH", "COMFORT_PLUG"):
|
||||||
entities.append(
|
entities.append(
|
||||||
SmappeeActuator(
|
SmappeeActuator(
|
||||||
smappee_base,
|
smappee_base,
|
||||||
|
@ -102,7 +102,7 @@ class SmappeeActuator(SwitchEntity):
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
"""Turn on Comport Plug."""
|
"""Turn on Comport Plug."""
|
||||||
if self._actuator_type in ["SWITCH", "COMFORT_PLUG"]:
|
if self._actuator_type in ("SWITCH", "COMFORT_PLUG"):
|
||||||
self._service_location.set_actuator_state(self._actuator_id, state="ON_ON")
|
self._service_location.set_actuator_state(self._actuator_id, state="ON_ON")
|
||||||
elif self._actuator_type == "INFINITY_OUTPUT_MODULE":
|
elif self._actuator_type == "INFINITY_OUTPUT_MODULE":
|
||||||
self._service_location.set_actuator_state(
|
self._service_location.set_actuator_state(
|
||||||
|
@ -111,7 +111,7 @@ class SmappeeActuator(SwitchEntity):
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
"""Turn off Comport Plug."""
|
"""Turn off Comport Plug."""
|
||||||
if self._actuator_type in ["SWITCH", "COMFORT_PLUG"]:
|
if self._actuator_type in ("SWITCH", "COMFORT_PLUG"):
|
||||||
self._service_location.set_actuator_state(
|
self._service_location.set_actuator_state(
|
||||||
self._actuator_id, state="OFF_OFF"
|
self._actuator_id, state="OFF_OFF"
|
||||||
)
|
)
|
||||||
|
|
|
@ -165,7 +165,7 @@ class SomfyClimate(SomfyEntity, ClimateEntity):
|
||||||
temperature = self._climate.get_night_temperature()
|
temperature = self._climate.get_night_temperature()
|
||||||
elif preset_mode == PRESET_FROST_GUARD:
|
elif preset_mode == PRESET_FROST_GUARD:
|
||||||
temperature = self._climate.get_frost_protection_temperature()
|
temperature = self._climate.get_frost_protection_temperature()
|
||||||
elif preset_mode in [PRESET_MANUAL, PRESET_GEOFENCING]:
|
elif preset_mode in (PRESET_MANUAL, PRESET_GEOFENCING):
|
||||||
temperature = self.target_temperature
|
temperature = self.target_temperature
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Preset mode not supported: {preset_mode}")
|
raise ValueError(f"Preset mode not supported: {preset_mode}")
|
||||||
|
|
|
@ -491,7 +491,7 @@ class SpotifyMediaPlayer(MediaPlayerEntity):
|
||||||
)
|
)
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
if media_content_type in [None, "library"]:
|
if media_content_type in (None, "library"):
|
||||||
return await self.hass.async_add_executor_job(library_payload)
|
return await self.hass.async_add_executor_job(library_payload)
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
|
|
|
@ -180,7 +180,7 @@ class StatisticsSensor(SensorEntity):
|
||||||
|
|
||||||
def _add_state_to_queue(self, new_state):
|
def _add_state_to_queue(self, new_state):
|
||||||
"""Add the state to the queue."""
|
"""Add the state to the queue."""
|
||||||
if new_state.state in [STATE_UNKNOWN, STATE_UNAVAILABLE]:
|
if new_state.state in (STATE_UNKNOWN, STATE_UNAVAILABLE):
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -414,20 +414,20 @@ def _update( # noqa: C901
|
||||||
err.pid,
|
err.pid,
|
||||||
err.name,
|
err.name,
|
||||||
)
|
)
|
||||||
elif type_ in ["network_out", "network_in"]:
|
elif type_ in ("network_out", "network_in"):
|
||||||
counters = _net_io_counters()
|
counters = _net_io_counters()
|
||||||
if data.argument in counters:
|
if data.argument in counters:
|
||||||
counter = counters[data.argument][IO_COUNTER[type_]]
|
counter = counters[data.argument][IO_COUNTER[type_]]
|
||||||
state = round(counter / 1024 ** 2, 1)
|
state = round(counter / 1024 ** 2, 1)
|
||||||
else:
|
else:
|
||||||
state = None
|
state = None
|
||||||
elif type_ in ["packets_out", "packets_in"]:
|
elif type_ in ("packets_out", "packets_in"):
|
||||||
counters = _net_io_counters()
|
counters = _net_io_counters()
|
||||||
if data.argument in counters:
|
if data.argument in counters:
|
||||||
state = counters[data.argument][IO_COUNTER[type_]]
|
state = counters[data.argument][IO_COUNTER[type_]]
|
||||||
else:
|
else:
|
||||||
state = None
|
state = None
|
||||||
elif type_ in ["throughput_network_out", "throughput_network_in"]:
|
elif type_ in ("throughput_network_out", "throughput_network_in"):
|
||||||
counters = _net_io_counters()
|
counters = _net_io_counters()
|
||||||
if data.argument in counters:
|
if data.argument in counters:
|
||||||
counter = counters[data.argument][IO_COUNTER[type_]]
|
counter = counters[data.argument][IO_COUNTER[type_]]
|
||||||
|
@ -445,7 +445,7 @@ def _update( # noqa: C901
|
||||||
value = counter
|
value = counter
|
||||||
else:
|
else:
|
||||||
state = None
|
state = None
|
||||||
elif type_ in ["ipv4_address", "ipv6_address"]:
|
elif type_ in ("ipv4_address", "ipv6_address"):
|
||||||
addresses = _net_if_addrs()
|
addresses = _net_if_addrs()
|
||||||
if data.argument in addresses:
|
if data.argument in addresses:
|
||||||
for addr in addresses[data.argument]:
|
for addr in addresses[data.argument]:
|
||||||
|
|
|
@ -465,7 +465,7 @@ class TemplateFan(TemplateEntity, FanEntity):
|
||||||
# Validate state
|
# Validate state
|
||||||
if result in _VALID_STATES:
|
if result in _VALID_STATES:
|
||||||
self._state = result
|
self._state = result
|
||||||
elif result in [STATE_UNAVAILABLE, STATE_UNKNOWN]:
|
elif result in (STATE_UNAVAILABLE, STATE_UNKNOWN):
|
||||||
self._state = None
|
self._state = None
|
||||||
else:
|
else:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
|
@ -529,7 +529,7 @@ class TemplateFan(TemplateEntity, FanEntity):
|
||||||
self._speed = speed
|
self._speed = speed
|
||||||
self._percentage = self.speed_to_percentage(speed)
|
self._percentage = self.speed_to_percentage(speed)
|
||||||
self._preset_mode = speed if speed in self.preset_modes else None
|
self._preset_mode = speed if speed in self.preset_modes else None
|
||||||
elif speed in [STATE_UNAVAILABLE, STATE_UNKNOWN]:
|
elif speed in (STATE_UNAVAILABLE, STATE_UNKNOWN):
|
||||||
self._speed = None
|
self._speed = None
|
||||||
self._percentage = 0
|
self._percentage = 0
|
||||||
self._preset_mode = None
|
self._preset_mode = None
|
||||||
|
@ -573,7 +573,7 @@ class TemplateFan(TemplateEntity, FanEntity):
|
||||||
self._speed = preset_mode
|
self._speed = preset_mode
|
||||||
self._percentage = None
|
self._percentage = None
|
||||||
self._preset_mode = preset_mode
|
self._preset_mode = preset_mode
|
||||||
elif preset_mode in [STATE_UNAVAILABLE, STATE_UNKNOWN]:
|
elif preset_mode in (STATE_UNAVAILABLE, STATE_UNKNOWN):
|
||||||
self._speed = None
|
self._speed = None
|
||||||
self._percentage = None
|
self._percentage = None
|
||||||
self._preset_mode = None
|
self._preset_mode = None
|
||||||
|
@ -594,7 +594,7 @@ class TemplateFan(TemplateEntity, FanEntity):
|
||||||
self._oscillating = True
|
self._oscillating = True
|
||||||
elif oscillating == "False" or oscillating is False:
|
elif oscillating == "False" or oscillating is False:
|
||||||
self._oscillating = False
|
self._oscillating = False
|
||||||
elif oscillating in [STATE_UNAVAILABLE, STATE_UNKNOWN]:
|
elif oscillating in (STATE_UNAVAILABLE, STATE_UNKNOWN):
|
||||||
self._oscillating = None
|
self._oscillating = None
|
||||||
else:
|
else:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
|
@ -608,7 +608,7 @@ class TemplateFan(TemplateEntity, FanEntity):
|
||||||
# Validate direction
|
# Validate direction
|
||||||
if direction in _VALID_DIRECTIONS:
|
if direction in _VALID_DIRECTIONS:
|
||||||
self._direction = direction
|
self._direction = direction
|
||||||
elif direction in [STATE_UNAVAILABLE, STATE_UNKNOWN]:
|
elif direction in (STATE_UNAVAILABLE, STATE_UNKNOWN):
|
||||||
self._direction = None
|
self._direction = None
|
||||||
else:
|
else:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
|
|
|
@ -44,7 +44,7 @@ class TeslaSensor(TeslaDevice, SensorEntity):
|
||||||
if self.type == "outside":
|
if self.type == "outside":
|
||||||
return self.tesla_device.get_outside_temp()
|
return self.tesla_device.get_outside_temp()
|
||||||
return self.tesla_device.get_inside_temp()
|
return self.tesla_device.get_inside_temp()
|
||||||
if self.tesla_device.type in ["range sensor", "mileage sensor"]:
|
if self.tesla_device.type in ("range sensor", "mileage sensor"):
|
||||||
units = self.tesla_device.measurement
|
units = self.tesla_device.measurement
|
||||||
if units == "LENGTH_MILES":
|
if units == "LENGTH_MILES":
|
||||||
return self.tesla_device.get_value()
|
return self.tesla_device.get_value()
|
||||||
|
|
|
@ -160,7 +160,7 @@ class ThermoworksSmokeSensor(SensorEntity):
|
||||||
}
|
}
|
||||||
|
|
||||||
# set extended attributes for main probe sensors
|
# set extended attributes for main probe sensors
|
||||||
if self.type in [PROBE_1, PROBE_2]:
|
if self.type in (PROBE_1, PROBE_2):
|
||||||
for key, val in values.items():
|
for key, val in values.items():
|
||||||
# add all attributes that don't contain any probe name
|
# add all attributes that don't contain any probe name
|
||||||
# or contain a matching probe name
|
# or contain a matching probe name
|
||||||
|
|
|
@ -286,7 +286,7 @@ class UpCloudServerEntity(CoordinatorEntity):
|
||||||
"""Return True if entity is available."""
|
"""Return True if entity is available."""
|
||||||
return super().available and STATE_MAP.get(
|
return super().available and STATE_MAP.get(
|
||||||
self._server.state, self._server.state
|
self._server.state, self._server.state
|
||||||
) in [STATE_ON, STATE_OFF]
|
) in (STATE_ON, STATE_OFF)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict[str, Any]:
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
|
|
|
@ -131,7 +131,7 @@ class UnifiVideoCamera(Camera):
|
||||||
|
|
||||||
return self._caminfo["recordingSettings"][
|
return self._caminfo["recordingSettings"][
|
||||||
"fullTimeRecordEnabled"
|
"fullTimeRecordEnabled"
|
||||||
] or recording_state in ["MOTION_INPROGRESS", "MOTION_FINISHED"]
|
] or recording_state in ("MOTION_INPROGRESS", "MOTION_FINISHED")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def motion_detection_enabled(self):
|
def motion_detection_enabled(self):
|
||||||
|
|
|
@ -32,7 +32,7 @@ RESULT_INVALID_AUTH = "invalid_auth"
|
||||||
def host_valid(host):
|
def host_valid(host):
|
||||||
"""Return True if hostname or IP address is valid."""
|
"""Return True if hostname or IP address is valid."""
|
||||||
try:
|
try:
|
||||||
if ipaddress.ip_address(host).version in [4, 6]:
|
if ipaddress.ip_address(host).version in (4, 6):
|
||||||
return True
|
return True
|
||||||
except ValueError:
|
except ValueError:
|
||||||
disallowed = re.compile(r"[^a-zA-Z\d\-]")
|
disallowed = re.compile(r"[^a-zA-Z\d\-]")
|
||||||
|
|
|
@ -87,7 +87,7 @@ async def async_setup_entry(
|
||||||
(
|
(
|
||||||
key
|
key
|
||||||
for key in config_entry.data.get(CONF_APPS, {})
|
for key in config_entry.data.get(CONF_APPS, {})
|
||||||
if key in [CONF_INCLUDE, CONF_EXCLUDE]
|
if key in (CONF_INCLUDE, CONF_EXCLUDE)
|
||||||
),
|
),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
|
|
@ -73,9 +73,9 @@ def _item_to_children_media_class(item, info=None):
|
||||||
def _item_to_media_class(item, parent_item=None):
|
def _item_to_media_class(item, parent_item=None):
|
||||||
if "type" not in item:
|
if "type" not in item:
|
||||||
return MEDIA_CLASS_DIRECTORY
|
return MEDIA_CLASS_DIRECTORY
|
||||||
if item["type"] in ["webradio", "mywebradio"]:
|
if item["type"] in ("webradio", "mywebradio"):
|
||||||
return MEDIA_CLASS_CHANNEL
|
return MEDIA_CLASS_CHANNEL
|
||||||
if item["type"] in ["song", "cuesong"]:
|
if item["type"] in ("song", "cuesong"):
|
||||||
return MEDIA_CLASS_TRACK
|
return MEDIA_CLASS_TRACK
|
||||||
if item.get("artist"):
|
if item.get("artist"):
|
||||||
return MEDIA_CLASS_ALBUM
|
return MEDIA_CLASS_ALBUM
|
||||||
|
|
|
@ -259,7 +259,7 @@ class Volumio(MediaPlayerEntity):
|
||||||
async def async_browse_media(self, media_content_type=None, media_content_id=None):
|
async def async_browse_media(self, media_content_type=None, media_content_id=None):
|
||||||
"""Implement the websocket media browsing helper."""
|
"""Implement the websocket media browsing helper."""
|
||||||
self.thumbnail_cache = {}
|
self.thumbnail_cache = {}
|
||||||
if media_content_type in [None, "library"]:
|
if media_content_type in (None, "library"):
|
||||||
return await browse_top_level(self._volumio)
|
return await browse_top_level(self._volumio)
|
||||||
|
|
||||||
return await browse_node(
|
return await browse_node(
|
||||||
|
|
|
@ -45,7 +45,7 @@ async def build_item_response(
|
||||||
"""Create response payload for the provided media query."""
|
"""Create response payload for the provided media query."""
|
||||||
apps: InstalledPackagesList = await client.smartglass.get_installed_apps(device_id)
|
apps: InstalledPackagesList = await client.smartglass.get_installed_apps(device_id)
|
||||||
|
|
||||||
if media_content_type in [None, "library"]:
|
if media_content_type in (None, "library"):
|
||||||
library_info = BrowseMedia(
|
library_info = BrowseMedia(
|
||||||
media_class=MEDIA_CLASS_DIRECTORY,
|
media_class=MEDIA_CLASS_DIRECTORY,
|
||||||
media_content_id="library",
|
media_content_id="library",
|
||||||
|
|
|
@ -32,23 +32,23 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
gateway = hass.data[DOMAIN][GATEWAYS_KEY][config_entry.entry_id]
|
gateway = hass.data[DOMAIN][GATEWAYS_KEY][config_entry.entry_id]
|
||||||
for entity in gateway.devices["binary_sensor"]:
|
for entity in gateway.devices["binary_sensor"]:
|
||||||
model = entity["model"]
|
model = entity["model"]
|
||||||
if model in ["motion", "sensor_motion", "sensor_motion.aq2"]:
|
if model in ("motion", "sensor_motion", "sensor_motion.aq2"):
|
||||||
entities.append(XiaomiMotionSensor(entity, hass, gateway, config_entry))
|
entities.append(XiaomiMotionSensor(entity, hass, gateway, config_entry))
|
||||||
elif model in ["magnet", "sensor_magnet", "sensor_magnet.aq2"]:
|
elif model in ("magnet", "sensor_magnet", "sensor_magnet.aq2"):
|
||||||
entities.append(XiaomiDoorSensor(entity, gateway, config_entry))
|
entities.append(XiaomiDoorSensor(entity, gateway, config_entry))
|
||||||
elif model == "sensor_wleak.aq1":
|
elif model == "sensor_wleak.aq1":
|
||||||
entities.append(XiaomiWaterLeakSensor(entity, gateway, config_entry))
|
entities.append(XiaomiWaterLeakSensor(entity, gateway, config_entry))
|
||||||
elif model in ["smoke", "sensor_smoke"]:
|
elif model in ("smoke", "sensor_smoke"):
|
||||||
entities.append(XiaomiSmokeSensor(entity, gateway, config_entry))
|
entities.append(XiaomiSmokeSensor(entity, gateway, config_entry))
|
||||||
elif model in ["natgas", "sensor_natgas"]:
|
elif model in ("natgas", "sensor_natgas"):
|
||||||
entities.append(XiaomiNatgasSensor(entity, gateway, config_entry))
|
entities.append(XiaomiNatgasSensor(entity, gateway, config_entry))
|
||||||
elif model in [
|
elif model in (
|
||||||
"switch",
|
"switch",
|
||||||
"sensor_switch",
|
"sensor_switch",
|
||||||
"sensor_switch.aq2",
|
"sensor_switch.aq2",
|
||||||
"sensor_switch.aq3",
|
"sensor_switch.aq3",
|
||||||
"remote.b1acn01",
|
"remote.b1acn01",
|
||||||
]:
|
):
|
||||||
if "proto" not in entity or int(entity["proto"][0:1]) == 1:
|
if "proto" not in entity or int(entity["proto"][0:1]) == 1:
|
||||||
data_key = "status"
|
data_key = "status"
|
||||||
else:
|
else:
|
||||||
|
@ -56,13 +56,13 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
entities.append(
|
entities.append(
|
||||||
XiaomiButton(entity, "Switch", data_key, hass, gateway, config_entry)
|
XiaomiButton(entity, "Switch", data_key, hass, gateway, config_entry)
|
||||||
)
|
)
|
||||||
elif model in [
|
elif model in (
|
||||||
"86sw1",
|
"86sw1",
|
||||||
"sensor_86sw1",
|
"sensor_86sw1",
|
||||||
"sensor_86sw1.aq1",
|
"sensor_86sw1.aq1",
|
||||||
"remote.b186acn01",
|
"remote.b186acn01",
|
||||||
"remote.b186acn02",
|
"remote.b186acn02",
|
||||||
]:
|
):
|
||||||
if "proto" not in entity or int(entity["proto"][0:1]) == 1:
|
if "proto" not in entity or int(entity["proto"][0:1]) == 1:
|
||||||
data_key = "channel_0"
|
data_key = "channel_0"
|
||||||
else:
|
else:
|
||||||
|
@ -72,13 +72,13 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
entity, "Wall Switch", data_key, hass, gateway, config_entry
|
entity, "Wall Switch", data_key, hass, gateway, config_entry
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif model in [
|
elif model in (
|
||||||
"86sw2",
|
"86sw2",
|
||||||
"sensor_86sw2",
|
"sensor_86sw2",
|
||||||
"sensor_86sw2.aq1",
|
"sensor_86sw2.aq1",
|
||||||
"remote.b286acn01",
|
"remote.b286acn01",
|
||||||
"remote.b286acn02",
|
"remote.b286acn02",
|
||||||
]:
|
):
|
||||||
if "proto" not in entity or int(entity["proto"][0:1]) == 1:
|
if "proto" not in entity or int(entity["proto"][0:1]) == 1:
|
||||||
data_key_left = "channel_0"
|
data_key_left = "channel_0"
|
||||||
data_key_right = "channel_1"
|
data_key_right = "channel_1"
|
||||||
|
@ -115,9 +115,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
config_entry,
|
config_entry,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif model in ["cube", "sensor_cube", "sensor_cube.aqgl01"]:
|
elif model in ("cube", "sensor_cube", "sensor_cube.aqgl01"):
|
||||||
entities.append(XiaomiCube(entity, hass, gateway, config_entry))
|
entities.append(XiaomiCube(entity, hass, gateway, config_entry))
|
||||||
elif model in ["vibration", "vibration.aq1"]:
|
elif model in ("vibration", "vibration.aq1"):
|
||||||
entities.append(
|
entities.append(
|
||||||
XiaomiVibration(entity, "Vibration", "status", gateway, config_entry)
|
XiaomiVibration(entity, "Vibration", "status", gateway, config_entry)
|
||||||
)
|
)
|
||||||
|
|
|
@ -16,7 +16,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
gateway = hass.data[DOMAIN][GATEWAYS_KEY][config_entry.entry_id]
|
gateway = hass.data[DOMAIN][GATEWAYS_KEY][config_entry.entry_id]
|
||||||
for device in gateway.devices["cover"]:
|
for device in gateway.devices["cover"]:
|
||||||
model = device["model"]
|
model = device["model"]
|
||||||
if model in ["curtain", "curtain.aq2", "curtain.hagl04"]:
|
if model in ("curtain", "curtain.aq2", "curtain.hagl04"):
|
||||||
if "proto" not in device or int(device["proto"][0:1]) == 1:
|
if "proto" not in device or int(device["proto"][0:1]) == 1:
|
||||||
data_key = DATA_KEY_PROTO_V1
|
data_key = DATA_KEY_PROTO_V1
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -24,7 +24,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
gateway = hass.data[DOMAIN][GATEWAYS_KEY][config_entry.entry_id]
|
gateway = hass.data[DOMAIN][GATEWAYS_KEY][config_entry.entry_id]
|
||||||
for device in gateway.devices["light"]:
|
for device in gateway.devices["light"]:
|
||||||
model = device["model"]
|
model = device["model"]
|
||||||
if model in ["gateway", "gateway.v3"]:
|
if model in ("gateway", "gateway.v3"):
|
||||||
entities.append(
|
entities.append(
|
||||||
XiaomiGatewayLight(device, "Gateway Light", gateway, config_entry)
|
XiaomiGatewayLight(device, "Gateway Light", gateway, config_entry)
|
||||||
)
|
)
|
||||||
|
|
|
@ -47,7 +47,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
entities.append(
|
entities.append(
|
||||||
XiaomiSensor(device, "Humidity", "humidity", gateway, config_entry)
|
XiaomiSensor(device, "Humidity", "humidity", gateway, config_entry)
|
||||||
)
|
)
|
||||||
elif device["model"] in ["weather", "weather.v1"]:
|
elif device["model"] in ("weather", "weather.v1"):
|
||||||
entities.append(
|
entities.append(
|
||||||
XiaomiSensor(
|
XiaomiSensor(
|
||||||
device, "Temperature", "temperature", gateway, config_entry
|
device, "Temperature", "temperature", gateway, config_entry
|
||||||
|
@ -63,13 +63,13 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
entities.append(
|
entities.append(
|
||||||
XiaomiSensor(device, "Illumination", "lux", gateway, config_entry)
|
XiaomiSensor(device, "Illumination", "lux", gateway, config_entry)
|
||||||
)
|
)
|
||||||
elif device["model"] in ["gateway", "gateway.v3", "acpartner.v3"]:
|
elif device["model"] in ("gateway", "gateway.v3", "acpartner.v3"):
|
||||||
entities.append(
|
entities.append(
|
||||||
XiaomiSensor(
|
XiaomiSensor(
|
||||||
device, "Illumination", "illumination", gateway, config_entry
|
device, "Illumination", "illumination", gateway, config_entry
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif device["model"] in ["vibration"]:
|
elif device["model"] in ("vibration",):
|
||||||
entities.append(
|
entities.append(
|
||||||
XiaomiSensor(
|
XiaomiSensor(
|
||||||
device, "Bed Activity", "bed_activity", gateway, config_entry
|
device, "Bed Activity", "bed_activity", gateway, config_entry
|
||||||
|
@ -151,13 +151,13 @@ class XiaomiSensor(XiaomiDevice, SensorEntity):
|
||||||
value = data.get(self._data_key)
|
value = data.get(self._data_key)
|
||||||
if value is None:
|
if value is None:
|
||||||
return False
|
return False
|
||||||
if self._data_key in ["coordination", "status"]:
|
if self._data_key in ("coordination", "status"):
|
||||||
self._state = value
|
self._state = value
|
||||||
return True
|
return True
|
||||||
value = float(value)
|
value = float(value)
|
||||||
if self._data_key in ["temperature", "humidity", "pressure"]:
|
if self._data_key in ("temperature", "humidity", "pressure"):
|
||||||
value /= 100
|
value /= 100
|
||||||
elif self._data_key in ["illumination"]:
|
elif self._data_key in ("illumination",):
|
||||||
value = max(value - 300, 0)
|
value = max(value - 300, 0)
|
||||||
if self._data_key == "temperature" and (value < -50 or value > 60):
|
if self._data_key == "temperature" and (value < -50 or value > 60):
|
||||||
return False
|
return False
|
||||||
|
@ -165,7 +165,7 @@ class XiaomiSensor(XiaomiDevice, SensorEntity):
|
||||||
return False
|
return False
|
||||||
if self._data_key == "pressure" and value == 0:
|
if self._data_key == "pressure" and value == 0:
|
||||||
return False
|
return False
|
||||||
if self._data_key in ["illumination", "lux"]:
|
if self._data_key in ("illumination", "lux"):
|
||||||
self._state = round(value)
|
self._state = round(value)
|
||||||
else:
|
else:
|
||||||
self._state = round(value, 1)
|
self._state = round(value, 1)
|
||||||
|
|
|
@ -37,34 +37,34 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
device, "Plug", data_key, True, gateway, config_entry
|
device, "Plug", data_key, True, gateway, config_entry
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif model in [
|
elif model in (
|
||||||
"ctrl_neutral1",
|
"ctrl_neutral1",
|
||||||
"ctrl_neutral1.aq1",
|
"ctrl_neutral1.aq1",
|
||||||
"switch_b1lacn02",
|
"switch_b1lacn02",
|
||||||
"switch.b1lacn02",
|
"switch.b1lacn02",
|
||||||
]:
|
):
|
||||||
entities.append(
|
entities.append(
|
||||||
XiaomiGenericSwitch(
|
XiaomiGenericSwitch(
|
||||||
device, "Wall Switch", "channel_0", False, gateway, config_entry
|
device, "Wall Switch", "channel_0", False, gateway, config_entry
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif model in [
|
elif model in (
|
||||||
"ctrl_ln1",
|
"ctrl_ln1",
|
||||||
"ctrl_ln1.aq1",
|
"ctrl_ln1.aq1",
|
||||||
"switch_b1nacn02",
|
"switch_b1nacn02",
|
||||||
"switch.b1nacn02",
|
"switch.b1nacn02",
|
||||||
]:
|
):
|
||||||
entities.append(
|
entities.append(
|
||||||
XiaomiGenericSwitch(
|
XiaomiGenericSwitch(
|
||||||
device, "Wall Switch LN", "channel_0", False, gateway, config_entry
|
device, "Wall Switch LN", "channel_0", False, gateway, config_entry
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif model in [
|
elif model in (
|
||||||
"ctrl_neutral2",
|
"ctrl_neutral2",
|
||||||
"ctrl_neutral2.aq1",
|
"ctrl_neutral2.aq1",
|
||||||
"switch_b2lacn02",
|
"switch_b2lacn02",
|
||||||
"switch.b2lacn02",
|
"switch.b2lacn02",
|
||||||
]:
|
):
|
||||||
entities.append(
|
entities.append(
|
||||||
XiaomiGenericSwitch(
|
XiaomiGenericSwitch(
|
||||||
device,
|
device,
|
||||||
|
@ -85,12 +85,12 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
config_entry,
|
config_entry,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif model in [
|
elif model in (
|
||||||
"ctrl_ln2",
|
"ctrl_ln2",
|
||||||
"ctrl_ln2.aq1",
|
"ctrl_ln2.aq1",
|
||||||
"switch_b2nacn02",
|
"switch_b2nacn02",
|
||||||
"switch.b2nacn02",
|
"switch.b2nacn02",
|
||||||
]:
|
):
|
||||||
entities.append(
|
entities.append(
|
||||||
XiaomiGenericSwitch(
|
XiaomiGenericSwitch(
|
||||||
device,
|
device,
|
||||||
|
@ -111,7 +111,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
config_entry,
|
config_entry,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif model in ["86plug", "ctrl_86plug", "ctrl_86plug.aq1"]:
|
elif model in ("86plug", "ctrl_86plug", "ctrl_86plug.aq1"):
|
||||||
if "proto" not in device or int(device["proto"][0:1]) == 1:
|
if "proto" not in device or int(device["proto"][0:1]) == 1:
|
||||||
data_key = "status"
|
data_key = "status"
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue