Use assignment expressions 12 (#57937)
This commit is contained in:
parent
7353ea5416
commit
4513ee4ea5
21 changed files with 30 additions and 62 deletions
|
@ -86,8 +86,7 @@ class AdaxDevice(ClimateEntity):
|
||||||
|
|
||||||
async def async_set_temperature(self, **kwargs: Any) -> None:
|
async def async_set_temperature(self, **kwargs: Any) -> None:
|
||||||
"""Set new target temperature."""
|
"""Set new target temperature."""
|
||||||
temperature = kwargs.get(ATTR_TEMPERATURE)
|
if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None:
|
||||||
if temperature is None:
|
|
||||||
return
|
return
|
||||||
await self._adax_data_handler.set_room_target_temperature(
|
await self._adax_data_handler.set_room_target_temperature(
|
||||||
self._device_id, temperature, True
|
self._device_id, temperature, True
|
||||||
|
|
|
@ -73,8 +73,7 @@ CONFIG_SCHEMA = vol.Schema(
|
||||||
|
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass, config):
|
||||||
"""Set up the AsusWrt integration."""
|
"""Set up the AsusWrt integration."""
|
||||||
conf = config.get(DOMAIN)
|
if (conf := config.get(DOMAIN)) is None:
|
||||||
if conf is None:
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# save the options from config yaml
|
# save the options from config yaml
|
||||||
|
|
|
@ -255,8 +255,7 @@ class DomainBlueprints:
|
||||||
|
|
||||||
def load_from_cache():
|
def load_from_cache():
|
||||||
"""Load blueprint from cache."""
|
"""Load blueprint from cache."""
|
||||||
blueprint = self._blueprints[blueprint_path]
|
if (blueprint := self._blueprints[blueprint_path]) is None:
|
||||||
if blueprint is None:
|
|
||||||
raise FailedToLoad(
|
raise FailedToLoad(
|
||||||
self.domain,
|
self.domain,
|
||||||
blueprint_path,
|
blueprint_path,
|
||||||
|
|
|
@ -73,8 +73,7 @@ class EnOceanLight(EnOceanEntity, LightEntity):
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
"""Turn the light source on or sets a specific dimmer value."""
|
"""Turn the light source on or sets a specific dimmer value."""
|
||||||
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
if (brightness := kwargs.get(ATTR_BRIGHTNESS)) is not None:
|
||||||
if brightness is not None:
|
|
||||||
self._brightness = brightness
|
self._brightness = brightness
|
||||||
|
|
||||||
bval = math.floor(self._brightness / 256.0 * 100.0)
|
bval = math.floor(self._brightness / 256.0 * 100.0)
|
||||||
|
|
|
@ -52,8 +52,7 @@ async def async_attach_trigger(hass, config, action, automation_info):
|
||||||
if not source_match(from_state, source) and not source_match(to_state, source):
|
if not source_match(from_state, source) and not source_match(to_state, source):
|
||||||
return
|
return
|
||||||
|
|
||||||
zone_state = hass.states.get(zone_entity_id)
|
if (zone_state := hass.states.get(zone_entity_id)) is None:
|
||||||
if zone_state is None:
|
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"Unable to execute automation %s: Zone %s not found",
|
"Unable to execute automation %s: Zone %s not found",
|
||||||
automation_info["name"],
|
automation_info["name"],
|
||||||
|
|
|
@ -150,8 +150,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||||
|
|
||||||
async def async_get_engine(hass, config, discovery_info=None):
|
async def async_get_engine(hass, config, discovery_info=None):
|
||||||
"""Set up Google Cloud TTS component."""
|
"""Set up Google Cloud TTS component."""
|
||||||
key_file = config.get(CONF_KEY_FILE)
|
if key_file := config.get(CONF_KEY_FILE):
|
||||||
if key_file:
|
|
||||||
key_file = hass.config.path(key_file)
|
key_file = hass.config.path(key_file)
|
||||||
if not os.path.isfile(key_file):
|
if not os.path.isfile(key_file):
|
||||||
_LOGGER.error("File %s doesn't exist", key_file)
|
_LOGGER.error("File %s doesn't exist", key_file)
|
||||||
|
|
|
@ -106,8 +106,7 @@ class ISYThermostatEntity(ISYNodeEntity, ClimateEntity):
|
||||||
@property
|
@property
|
||||||
def temperature_unit(self) -> str:
|
def temperature_unit(self) -> str:
|
||||||
"""Return the unit of measurement."""
|
"""Return the unit of measurement."""
|
||||||
uom = self._node.aux_properties.get(PROP_UOM)
|
if not (uom := self._node.aux_properties.get(PROP_UOM)):
|
||||||
if not uom:
|
|
||||||
return self.hass.config.units.temperature_unit
|
return self.hass.config.units.temperature_unit
|
||||||
if uom.value == UOM_ISY_CELSIUS:
|
if uom.value == UOM_ISY_CELSIUS:
|
||||||
return TEMP_CELSIUS
|
return TEMP_CELSIUS
|
||||||
|
@ -117,16 +116,14 @@ class ISYThermostatEntity(ISYNodeEntity, ClimateEntity):
|
||||||
@property
|
@property
|
||||||
def current_humidity(self) -> int | None:
|
def current_humidity(self) -> int | None:
|
||||||
"""Return the current humidity."""
|
"""Return the current humidity."""
|
||||||
humidity = self._node.aux_properties.get(PROP_HUMIDITY)
|
if not (humidity := self._node.aux_properties.get(PROP_HUMIDITY)):
|
||||||
if not humidity:
|
|
||||||
return None
|
return None
|
||||||
return int(humidity.value)
|
return int(humidity.value)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_mode(self) -> str | None:
|
def hvac_mode(self) -> str | None:
|
||||||
"""Return hvac operation ie. heat, cool mode."""
|
"""Return hvac operation ie. heat, cool mode."""
|
||||||
hvac_mode = self._node.aux_properties.get(CMD_CLIMATE_MODE)
|
if not (hvac_mode := self._node.aux_properties.get(CMD_CLIMATE_MODE)):
|
||||||
if not hvac_mode:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Which state values used depends on the mode property's UOM:
|
# Which state values used depends on the mode property's UOM:
|
||||||
|
|
|
@ -57,8 +57,7 @@ class ISYSensorEntity(ISYNodeEntity, SensorEntity):
|
||||||
return UOM_FRIENDLY_NAME.get(uom[0], uom[0])
|
return UOM_FRIENDLY_NAME.get(uom[0], uom[0])
|
||||||
|
|
||||||
# Special cases for ISY UOM index units:
|
# Special cases for ISY UOM index units:
|
||||||
isy_states = UOM_TO_STATES.get(uom)
|
if isy_states := UOM_TO_STATES.get(uom):
|
||||||
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):
|
||||||
|
|
|
@ -280,8 +280,7 @@ class OctoPrintAPI:
|
||||||
|
|
||||||
def update(self, sensor_type, end_point, group, tool=None):
|
def update(self, sensor_type, end_point, group, tool=None):
|
||||||
"""Return the value for sensor_type from the provided endpoint."""
|
"""Return the value for sensor_type from the provided endpoint."""
|
||||||
response = self.get(end_point)
|
if (response := self.get(end_point)) is not None:
|
||||||
if response is not None:
|
|
||||||
return get_value_from_json(response, sensor_type, group, tool)
|
return get_value_from_json(response, sensor_type, group, tool)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
|
@ -85,9 +85,8 @@ WEBHOOK_SCHEMA = vol.Schema(
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Configure based on config entry."""
|
"""Configure based on config entry."""
|
||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
use_webhook = entry.data[CONF_USE_WEBHOOK]
|
|
||||||
|
|
||||||
if use_webhook:
|
if entry.data[CONF_USE_WEBHOOK]:
|
||||||
async_setup_webhook(hass, entry)
|
async_setup_webhook(hass, entry)
|
||||||
else:
|
else:
|
||||||
await async_setup_coordinator(hass, entry)
|
await async_setup_coordinator(hass, entry)
|
||||||
|
|
|
@ -131,8 +131,7 @@ class PlexFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
"""Begin manual configuration."""
|
"""Begin manual configuration."""
|
||||||
if user_input is not None and errors is None:
|
if user_input is not None and errors is None:
|
||||||
user_input.pop(CONF_URL, None)
|
user_input.pop(CONF_URL, None)
|
||||||
host = user_input.get(CONF_HOST)
|
if host := user_input.get(CONF_HOST):
|
||||||
if host:
|
|
||||||
port = user_input[CONF_PORT]
|
port = user_input[CONF_PORT]
|
||||||
prefix = "https" if user_input.get(CONF_SSL) else "http"
|
prefix = "https" if user_input.get(CONF_SSL) else "http"
|
||||||
user_input[CONF_URL] = f"{prefix}://{host}:{port}"
|
user_input[CONF_URL] = f"{prefix}://{host}:{port}"
|
||||||
|
|
|
@ -259,8 +259,7 @@ class PlexServer:
|
||||||
"""Process a session payload received from a websocket callback."""
|
"""Process a session payload received from a websocket callback."""
|
||||||
session_payload = payload["PlaySessionStateNotification"][0]
|
session_payload = payload["PlaySessionStateNotification"][0]
|
||||||
|
|
||||||
state = session_payload["state"]
|
if (state := session_payload["state"]) == "buffering":
|
||||||
if state == "buffering":
|
|
||||||
return
|
return
|
||||||
|
|
||||||
session_key = int(session_payload["sessionKey"])
|
session_key = int(session_payload["sessionKey"])
|
||||||
|
|
|
@ -148,8 +148,7 @@ class PrometheusMetrics:
|
||||||
|
|
||||||
def handle_event(self, event):
|
def handle_event(self, event):
|
||||||
"""Listen for new messages on the bus, and add them to Prometheus."""
|
"""Listen for new messages on the bus, and add them to Prometheus."""
|
||||||
state = event.data.get("new_state")
|
if (state := event.data.get("new_state")) is None:
|
||||||
if state is None:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
entity_id = state.entity_id
|
entity_id = state.entity_id
|
||||||
|
@ -318,8 +317,7 @@ class PrometheusMetrics:
|
||||||
metric.labels(**self._labels(state)).set(value)
|
metric.labels(**self._labels(state)).set(value)
|
||||||
|
|
||||||
def _handle_climate_temp(self, state, attr, metric_name, metric_description):
|
def _handle_climate_temp(self, state, attr, metric_name, metric_description):
|
||||||
temp = state.attributes.get(attr)
|
if temp := state.attributes.get(attr):
|
||||||
if temp:
|
|
||||||
if self._climate_units == TEMP_FAHRENHEIT:
|
if self._climate_units == TEMP_FAHRENHEIT:
|
||||||
temp = fahrenheit_to_celsius(temp)
|
temp = fahrenheit_to_celsius(temp)
|
||||||
metric = self._metric(
|
metric = self._metric(
|
||||||
|
@ -355,8 +353,7 @@ class PrometheusMetrics:
|
||||||
"Current temperature in degrees Celsius",
|
"Current temperature in degrees Celsius",
|
||||||
)
|
)
|
||||||
|
|
||||||
current_action = state.attributes.get(ATTR_HVAC_ACTION)
|
if current_action := state.attributes.get(ATTR_HVAC_ACTION):
|
||||||
if current_action:
|
|
||||||
metric = self._metric(
|
metric = self._metric(
|
||||||
"climate_action",
|
"climate_action",
|
||||||
self.prometheus_cli.Gauge,
|
self.prometheus_cli.Gauge,
|
||||||
|
|
|
@ -30,9 +30,7 @@ async def _async_reproduce_state(
|
||||||
reproduce_options: dict[str, Any] | None = None,
|
reproduce_options: dict[str, Any] | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Reproduce a single state."""
|
"""Reproduce a single state."""
|
||||||
cur_state = hass.states.get(state.entity_id)
|
if (cur_state := hass.states.get(state.entity_id)) is None:
|
||||||
|
|
||||||
if cur_state is None:
|
|
||||||
_LOGGER.warning("Unable to find entity %s", state.entity_id)
|
_LOGGER.warning("Unable to find entity %s", state.entity_id)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -79,8 +79,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the Shelly component."""
|
"""Set up the Shelly component."""
|
||||||
hass.data[DOMAIN] = {DATA_CONFIG_ENTRY: {}}
|
hass.data[DOMAIN] = {DATA_CONFIG_ENTRY: {}}
|
||||||
|
|
||||||
conf = config.get(DOMAIN)
|
if (conf := config.get(DOMAIN)) is not None:
|
||||||
if conf is not None:
|
|
||||||
hass.data[DOMAIN][CONF_COAP_PORT] = conf[CONF_COAP_PORT]
|
hass.data[DOMAIN][CONF_COAP_PORT] = conf[CONF_COAP_PORT]
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -233,9 +232,8 @@ class BlockDeviceWrapper(update_coordinator.DataUpdateCoordinator):
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the Shelly device wrapper."""
|
"""Initialize the Shelly device wrapper."""
|
||||||
self.device_id: str | None = None
|
self.device_id: str | None = None
|
||||||
sleep_period = entry.data["sleep_period"]
|
|
||||||
|
|
||||||
if sleep_period:
|
if sleep_period := entry.data["sleep_period"]:
|
||||||
update_interval = SLEEP_PERIOD_MULTIPLIER * sleep_period
|
update_interval = SLEEP_PERIOD_MULTIPLIER * sleep_period
|
||||||
else:
|
else:
|
||||||
update_interval = (
|
update_interval = (
|
||||||
|
|
|
@ -82,15 +82,13 @@ async def async_setup_entry(hass, config_entry):
|
||||||
async def add_item_service(call):
|
async def add_item_service(call):
|
||||||
"""Add an item with `name`."""
|
"""Add an item with `name`."""
|
||||||
data = hass.data[DOMAIN]
|
data = hass.data[DOMAIN]
|
||||||
name = call.data.get(ATTR_NAME)
|
if (name := call.data.get(ATTR_NAME)) is not None:
|
||||||
if name is not None:
|
|
||||||
await data.async_add(name)
|
await data.async_add(name)
|
||||||
|
|
||||||
async def complete_item_service(call):
|
async def complete_item_service(call):
|
||||||
"""Mark the item provided via `name` as completed."""
|
"""Mark the item provided via `name` as completed."""
|
||||||
data = hass.data[DOMAIN]
|
data = hass.data[DOMAIN]
|
||||||
name = call.data.get(ATTR_NAME)
|
if (name := call.data.get(ATTR_NAME)) is None:
|
||||||
if name is None:
|
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
item = [item for item in data.items if item["name"] == name][0]
|
item = [item for item in data.items if item["name"] == name][0]
|
||||||
|
@ -102,8 +100,7 @@ async def async_setup_entry(hass, config_entry):
|
||||||
async def incomplete_item_service(call):
|
async def incomplete_item_service(call):
|
||||||
"""Mark the item provided via `name` as incomplete."""
|
"""Mark the item provided via `name` as incomplete."""
|
||||||
data = hass.data[DOMAIN]
|
data = hass.data[DOMAIN]
|
||||||
name = call.data.get(ATTR_NAME)
|
if (name := call.data.get(ATTR_NAME)) is None:
|
||||||
if name is None:
|
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
item = [item for item in data.items if item["name"] == name][0]
|
item = [item for item in data.items if item["name"] == name][0]
|
||||||
|
|
|
@ -61,8 +61,7 @@ def _parse_legacy_options(
|
||||||
)
|
)
|
||||||
|
|
||||||
# Parsing of sensors configuration
|
# Parsing of sensors configuration
|
||||||
config_sensors = entry.data.get(CONF_SENSORS)
|
if not (config_sensors := entry.data.get(CONF_SENSORS)):
|
||||||
if not config_sensors:
|
|
||||||
return []
|
return []
|
||||||
|
|
||||||
# Support import of legacy config that should have been removed from 0.99, but was still functional
|
# Support import of legacy config that should have been removed from 0.99, but was still functional
|
||||||
|
|
|
@ -207,8 +207,7 @@ class UtilityMeterSensor(RestoreEntity, SensorEntity):
|
||||||
@callback
|
@callback
|
||||||
def async_tariff_change(self, event):
|
def async_tariff_change(self, event):
|
||||||
"""Handle tariff changes."""
|
"""Handle tariff changes."""
|
||||||
new_state = event.data.get("new_state")
|
if (new_state := event.data.get("new_state")) is None:
|
||||||
if new_state is None:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
self._change_status(new_state.state)
|
self._change_status(new_state.state)
|
||||||
|
|
|
@ -102,8 +102,7 @@ def _list_payload(item, children=None):
|
||||||
|
|
||||||
def _raw_item_payload(entity, item, parent_item=None, title=None, info=None):
|
def _raw_item_payload(entity, item, parent_item=None, title=None, info=None):
|
||||||
if "type" in item:
|
if "type" in item:
|
||||||
thumbnail = item.get("albumart")
|
if thumbnail := item.get("albumart"):
|
||||||
if thumbnail:
|
|
||||||
item_hash = str(hash(thumbnail))
|
item_hash = str(hash(thumbnail))
|
||||||
entity.thumbnail_cache.setdefault(item_hash, thumbnail)
|
entity.thumbnail_cache.setdefault(item_hash, thumbnail)
|
||||||
thumbnail = entity.get_browse_image_url(MEDIA_TYPE_MUSIC, item_hash)
|
thumbnail = entity.get_browse_image_url(MEDIA_TYPE_MUSIC, item_hash)
|
||||||
|
@ -156,8 +155,7 @@ async def browse_node(entity, media_library, media_content_type, media_content_i
|
||||||
for item in first_list["items"]
|
for item in first_list["items"]
|
||||||
]
|
]
|
||||||
info = navigation.get("info")
|
info = navigation.get("info")
|
||||||
title = first_list.get("title")
|
if not (title := first_list.get("title")):
|
||||||
if not title:
|
|
||||||
if info:
|
if info:
|
||||||
title = f"{info.get('album')} ({info.get('artist')})"
|
title = f"{info.get('album')} ({info.get('artist')})"
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -53,9 +53,7 @@ async def _async_reproduce_state(
|
||||||
reproduce_options: dict[str, Any] | None = None,
|
reproduce_options: dict[str, Any] | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Reproduce a single state."""
|
"""Reproduce a single state."""
|
||||||
cur_state = hass.states.get(state.entity_id)
|
if (cur_state := hass.states.get(state.entity_id)) is None:
|
||||||
|
|
||||||
if cur_state is None:
|
|
||||||
_LOGGER.warning("Unable to find entity %s", state.entity_id)
|
_LOGGER.warning("Unable to find entity %s", state.entity_id)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -34,16 +34,14 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the Zabbix sensor platform."""
|
"""Set up the Zabbix sensor platform."""
|
||||||
sensors = []
|
sensors = []
|
||||||
|
|
||||||
zapi = hass.data[zabbix.DOMAIN]
|
if not (zapi := hass.data[zabbix.DOMAIN]):
|
||||||
if not zapi:
|
|
||||||
_LOGGER.error("Zabbix integration hasn't been loaded? zapi is None")
|
_LOGGER.error("Zabbix integration hasn't been loaded? zapi is None")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
_LOGGER.info("Connected to Zabbix API Version %s", zapi.api_version())
|
_LOGGER.info("Connected to Zabbix API Version %s", zapi.api_version())
|
||||||
|
|
||||||
trigger_conf = config.get(_CONF_TRIGGERS)
|
|
||||||
# The following code seems overly complex. Need to think about this...
|
# The following code seems overly complex. Need to think about this...
|
||||||
if trigger_conf:
|
if trigger_conf := config.get(_CONF_TRIGGERS):
|
||||||
hostids = trigger_conf.get(_CONF_HOSTIDS)
|
hostids = trigger_conf.get(_CONF_HOSTIDS)
|
||||||
individual = trigger_conf.get(_CONF_INDIVIDUAL)
|
individual = trigger_conf.get(_CONF_INDIVIDUAL)
|
||||||
name = trigger_conf.get(CONF_NAME)
|
name = trigger_conf.get(CONF_NAME)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue