mirror of
https://github.com/home-assistant/core
synced 2024-07-27 18:58:57 +02:00
Merge of nested IF-IF cases - E-G (#48367)
This commit is contained in:
parent
786023fce4
commit
0d595a2845
@ -115,8 +115,7 @@ class EbusdData:
|
||||
try:
|
||||
_LOGGER.debug("Opening socket to ebusd %s", name)
|
||||
command_result = ebusdpy.write(self._address, self._circuit, name, value)
|
||||
if command_result is not None:
|
||||
if "done" not in command_result:
|
||||
_LOGGER.warning("Write command failed: %s", name)
|
||||
if command_result is not None and "done" not in command_result:
|
||||
_LOGGER.warning("Write command failed: %s", name)
|
||||
except RuntimeError as err:
|
||||
_LOGGER.error(err)
|
||||
|
@ -170,10 +170,13 @@ class Monitor:
|
||||
)
|
||||
|
||||
for dev in self.devices:
|
||||
if dev.namespace == namespace and dev.instance == instance:
|
||||
if dev.temperature != temperature:
|
||||
dev.temperature = temperature
|
||||
dev.schedule_update_ha_state()
|
||||
if (
|
||||
dev.namespace == namespace
|
||||
and dev.instance == instance
|
||||
and dev.temperature != temperature
|
||||
):
|
||||
dev.temperature = temperature
|
||||
dev.schedule_update_ha_state()
|
||||
|
||||
def stop(self):
|
||||
"""Signal runner to stop and join thread."""
|
||||
|
@ -96,12 +96,13 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||
active_emby_devices[dev_id] = new
|
||||
new_devices.append(new)
|
||||
|
||||
elif dev_id in inactive_emby_devices:
|
||||
if emby.devices[dev_id].state != "Off":
|
||||
add = inactive_emby_devices.pop(dev_id)
|
||||
active_emby_devices[dev_id] = add
|
||||
_LOGGER.debug("Showing %s, item: %s", dev_id, add)
|
||||
add.set_available(True)
|
||||
elif (
|
||||
dev_id in inactive_emby_devices and emby.devices[dev_id].state != "Off"
|
||||
):
|
||||
add = inactive_emby_devices.pop(dev_id)
|
||||
active_emby_devices[dev_id] = add
|
||||
_LOGGER.debug("Showing %s, item: %s", dev_id, add)
|
||||
add.set_available(True)
|
||||
|
||||
if new_devices:
|
||||
_LOGGER.debug("Adding new devices: %s", new_devices)
|
||||
|
@ -92,13 +92,11 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
|
||||
for elem in data.data:
|
||||
|
||||
if exclude_feeds is not None:
|
||||
if int(elem["id"]) in exclude_feeds:
|
||||
continue
|
||||
if exclude_feeds is not None and int(elem["id"]) in exclude_feeds:
|
||||
continue
|
||||
|
||||
if include_only_feeds is not None:
|
||||
if int(elem["id"]) not in include_only_feeds:
|
||||
continue
|
||||
if include_only_feeds is not None and int(elem["id"]) not in include_only_feeds:
|
||||
continue
|
||||
|
||||
name = None
|
||||
if sensor_names is not None:
|
||||
|
@ -439,11 +439,13 @@ class HueOneLightChangeView(HomeAssistantView):
|
||||
# saturation and color temp
|
||||
if entity.domain == light.DOMAIN:
|
||||
if parsed[STATE_ON]:
|
||||
if entity_features & SUPPORT_BRIGHTNESS:
|
||||
if parsed[STATE_BRIGHTNESS] is not None:
|
||||
data[ATTR_BRIGHTNESS] = hue_brightness_to_hass(
|
||||
parsed[STATE_BRIGHTNESS]
|
||||
)
|
||||
if (
|
||||
entity_features & SUPPORT_BRIGHTNESS
|
||||
and parsed[STATE_BRIGHTNESS] is not None
|
||||
):
|
||||
data[ATTR_BRIGHTNESS] = hue_brightness_to_hass(
|
||||
parsed[STATE_BRIGHTNESS]
|
||||
)
|
||||
|
||||
if entity_features & SUPPORT_COLOR:
|
||||
if any((parsed[STATE_HUE], parsed[STATE_SATURATION])):
|
||||
@ -466,13 +468,17 @@ class HueOneLightChangeView(HomeAssistantView):
|
||||
if parsed[STATE_XY] is not None:
|
||||
data[ATTR_XY_COLOR] = parsed[STATE_XY]
|
||||
|
||||
if entity_features & SUPPORT_COLOR_TEMP:
|
||||
if parsed[STATE_COLOR_TEMP] is not None:
|
||||
data[ATTR_COLOR_TEMP] = parsed[STATE_COLOR_TEMP]
|
||||
if (
|
||||
entity_features & SUPPORT_COLOR_TEMP
|
||||
and parsed[STATE_COLOR_TEMP] is not None
|
||||
):
|
||||
data[ATTR_COLOR_TEMP] = parsed[STATE_COLOR_TEMP]
|
||||
|
||||
if entity_features & SUPPORT_TRANSITION:
|
||||
if parsed[STATE_TRANSITON] is not None:
|
||||
data[ATTR_TRANSITION] = parsed[STATE_TRANSITON] / 10
|
||||
if (
|
||||
entity_features & SUPPORT_TRANSITION
|
||||
and parsed[STATE_TRANSITON] is not None
|
||||
):
|
||||
data[ATTR_TRANSITION] = parsed[STATE_TRANSITON] / 10
|
||||
|
||||
# If the requested entity is a script, add some variables
|
||||
elif entity.domain == script.DOMAIN:
|
||||
@ -489,11 +495,13 @@ class HueOneLightChangeView(HomeAssistantView):
|
||||
# only setting the temperature
|
||||
service = None
|
||||
|
||||
if entity_features & SUPPORT_TARGET_TEMPERATURE:
|
||||
if parsed[STATE_BRIGHTNESS] is not None:
|
||||
domain = entity.domain
|
||||
service = SERVICE_SET_TEMPERATURE
|
||||
data[ATTR_TEMPERATURE] = parsed[STATE_BRIGHTNESS]
|
||||
if (
|
||||
entity_features & SUPPORT_TARGET_TEMPERATURE
|
||||
and parsed[STATE_BRIGHTNESS] is not None
|
||||
):
|
||||
domain = entity.domain
|
||||
service = SERVICE_SET_TEMPERATURE
|
||||
data[ATTR_TEMPERATURE] = parsed[STATE_BRIGHTNESS]
|
||||
|
||||
# If the requested entity is a humidifier, set the humidity
|
||||
elif entity.domain == humidifier.DOMAIN:
|
||||
@ -505,43 +513,48 @@ class HueOneLightChangeView(HomeAssistantView):
|
||||
|
||||
# If the requested entity is a media player, convert to volume
|
||||
elif entity.domain == media_player.DOMAIN:
|
||||
if entity_features & SUPPORT_VOLUME_SET:
|
||||
if parsed[STATE_BRIGHTNESS] is not None:
|
||||
turn_on_needed = True
|
||||
domain = entity.domain
|
||||
service = SERVICE_VOLUME_SET
|
||||
# Convert 0-100 to 0.0-1.0
|
||||
data[ATTR_MEDIA_VOLUME_LEVEL] = parsed[STATE_BRIGHTNESS] / 100.0
|
||||
if (
|
||||
entity_features & SUPPORT_VOLUME_SET
|
||||
and parsed[STATE_BRIGHTNESS] is not None
|
||||
):
|
||||
turn_on_needed = True
|
||||
domain = entity.domain
|
||||
service = SERVICE_VOLUME_SET
|
||||
# Convert 0-100 to 0.0-1.0
|
||||
data[ATTR_MEDIA_VOLUME_LEVEL] = parsed[STATE_BRIGHTNESS] / 100.0
|
||||
|
||||
# If the requested entity is a cover, convert to open_cover/close_cover
|
||||
elif entity.domain == cover.DOMAIN:
|
||||
domain = entity.domain
|
||||
service = SERVICE_CLOSE_COVER
|
||||
if service == SERVICE_TURN_ON:
|
||||
service = SERVICE_OPEN_COVER
|
||||
else:
|
||||
service = SERVICE_CLOSE_COVER
|
||||
|
||||
if entity_features & SUPPORT_SET_POSITION:
|
||||
if parsed[STATE_BRIGHTNESS] is not None:
|
||||
domain = entity.domain
|
||||
service = SERVICE_SET_COVER_POSITION
|
||||
data[ATTR_POSITION] = parsed[STATE_BRIGHTNESS]
|
||||
if (
|
||||
entity_features & SUPPORT_SET_POSITION
|
||||
and parsed[STATE_BRIGHTNESS] is not None
|
||||
):
|
||||
domain = entity.domain
|
||||
service = SERVICE_SET_COVER_POSITION
|
||||
data[ATTR_POSITION] = parsed[STATE_BRIGHTNESS]
|
||||
|
||||
# If the requested entity is a fan, convert to speed
|
||||
elif entity.domain == fan.DOMAIN:
|
||||
if entity_features & SUPPORT_SET_SPEED:
|
||||
if parsed[STATE_BRIGHTNESS] is not None:
|
||||
domain = entity.domain
|
||||
# Convert 0-100 to a fan speed
|
||||
brightness = parsed[STATE_BRIGHTNESS]
|
||||
if brightness == 0:
|
||||
data[ATTR_SPEED] = SPEED_OFF
|
||||
elif 0 < brightness <= 33.3:
|
||||
data[ATTR_SPEED] = SPEED_LOW
|
||||
elif 33.3 < brightness <= 66.6:
|
||||
data[ATTR_SPEED] = SPEED_MEDIUM
|
||||
elif 66.6 < brightness <= 100:
|
||||
data[ATTR_SPEED] = SPEED_HIGH
|
||||
elif (
|
||||
entity.domain == fan.DOMAIN
|
||||
and entity_features & SUPPORT_SET_SPEED
|
||||
and parsed[STATE_BRIGHTNESS] is not None
|
||||
):
|
||||
domain = entity.domain
|
||||
# Convert 0-100 to a fan speed
|
||||
brightness = parsed[STATE_BRIGHTNESS]
|
||||
if brightness == 0:
|
||||
data[ATTR_SPEED] = SPEED_OFF
|
||||
elif 0 < brightness <= 33.3:
|
||||
data[ATTR_SPEED] = SPEED_LOW
|
||||
elif 33.3 < brightness <= 66.6:
|
||||
data[ATTR_SPEED] = SPEED_MEDIUM
|
||||
elif 66.6 < brightness <= 100:
|
||||
data[ATTR_SPEED] = SPEED_HIGH
|
||||
|
||||
# Map the off command to on
|
||||
if entity.domain in config.off_maps_to_on_domains:
|
||||
|
@ -90,9 +90,11 @@ class BanSensor(SensorEntity):
|
||||
if len(self.ban_dict[STATE_ALL_BANS]) > 10:
|
||||
self.ban_dict[STATE_ALL_BANS].pop(0)
|
||||
|
||||
elif entry[0] == "Unban":
|
||||
if current_ip in self.ban_dict[STATE_CURRENT_BANS]:
|
||||
self.ban_dict[STATE_CURRENT_BANS].remove(current_ip)
|
||||
elif (
|
||||
entry[0] == "Unban"
|
||||
and current_ip in self.ban_dict[STATE_CURRENT_BANS]
|
||||
):
|
||||
self.ban_dict[STATE_CURRENT_BANS].remove(current_ip)
|
||||
|
||||
if self.ban_dict[STATE_CURRENT_BANS]:
|
||||
self.last_ban = self.ban_dict[STATE_CURRENT_BANS][-1]
|
||||
|
@ -459,9 +459,8 @@ class FanEntity(ToggleEntity):
|
||||
@property
|
||||
def percentage(self) -> int | None:
|
||||
"""Return the current speed as a percentage."""
|
||||
if not self._implemented_preset_mode:
|
||||
if self.speed in self.preset_modes:
|
||||
return None
|
||||
if not self._implemented_preset_mode and self.speed in self.preset_modes:
|
||||
return None
|
||||
if not self._implemented_percentage:
|
||||
return self.speed_to_percentage(self.speed)
|
||||
return 0
|
||||
|
@ -120,9 +120,8 @@ class GaradgetCover(CoverEntity):
|
||||
|
||||
def __del__(self):
|
||||
"""Try to remove token."""
|
||||
if self._obtained_token is True:
|
||||
if self.access_token is not None:
|
||||
self.remove_token()
|
||||
if self._obtained_token is True and self.access_token is not None:
|
||||
self.remove_token()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
@ -239,10 +238,12 @@ class GaradgetCover(CoverEntity):
|
||||
)
|
||||
self._state = STATE_OFFLINE
|
||||
|
||||
if self._state not in [STATE_CLOSING, STATE_OPENING]:
|
||||
if self._unsub_listener_cover is not None:
|
||||
self._unsub_listener_cover()
|
||||
self._unsub_listener_cover = None
|
||||
if (
|
||||
self._state not in [STATE_CLOSING, STATE_OPENING]
|
||||
and self._unsub_listener_cover is not None
|
||||
):
|
||||
self._unsub_listener_cover()
|
||||
self._unsub_listener_cover = None
|
||||
|
||||
def _get_variable(self, var):
|
||||
"""Get latest status."""
|
||||
|
@ -442,28 +442,27 @@ class GenericThermostat(ClimateEntity, RestoreEntity):
|
||||
if not self._active or self._hvac_mode == HVAC_MODE_OFF:
|
||||
return
|
||||
|
||||
if not force and time is None:
|
||||
# If the `force` argument is True, we
|
||||
# ignore `min_cycle_duration`.
|
||||
# If the `time` argument is not none, we were invoked for
|
||||
# keep-alive purposes, and `min_cycle_duration` is irrelevant.
|
||||
if self.min_cycle_duration:
|
||||
if self._is_device_active:
|
||||
current_state = STATE_ON
|
||||
else:
|
||||
current_state = HVAC_MODE_OFF
|
||||
try:
|
||||
long_enough = condition.state(
|
||||
self.hass,
|
||||
self.heater_entity_id,
|
||||
current_state,
|
||||
self.min_cycle_duration,
|
||||
)
|
||||
except ConditionError:
|
||||
long_enough = False
|
||||
# If the `force` argument is True, we
|
||||
# ignore `min_cycle_duration`.
|
||||
# If the `time` argument is not none, we were invoked for
|
||||
# keep-alive purposes, and `min_cycle_duration` is irrelevant.
|
||||
if not force and time is None and self.min_cycle_duration:
|
||||
if self._is_device_active:
|
||||
current_state = STATE_ON
|
||||
else:
|
||||
current_state = HVAC_MODE_OFF
|
||||
try:
|
||||
long_enough = condition.state(
|
||||
self.hass,
|
||||
self.heater_entity_id,
|
||||
current_state,
|
||||
self.min_cycle_duration,
|
||||
)
|
||||
except ConditionError:
|
||||
long_enough = False
|
||||
|
||||
if not long_enough:
|
||||
return
|
||||
if not long_enough:
|
||||
return
|
||||
|
||||
too_cold = self._target_temp >= self._cur_temp + self._cold_tolerance
|
||||
too_hot = self._cur_temp >= self._target_temp + self._hot_tolerance
|
||||
|
@ -17,45 +17,44 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
for sensor_type, sensor_details in SENSOR_TYPES.items():
|
||||
if sensor_details[0] not in client.api.data:
|
||||
continue
|
||||
if sensor_details[0] in client.api.data:
|
||||
if sensor_details[0] == "fs":
|
||||
# fs will provide a list of disks attached
|
||||
for disk in client.api.data[sensor_details[0]]:
|
||||
dev.append(
|
||||
GlancesSensor(
|
||||
client,
|
||||
name,
|
||||
disk["mnt_point"],
|
||||
SENSOR_TYPES[sensor_type][1],
|
||||
sensor_type,
|
||||
SENSOR_TYPES[sensor_type],
|
||||
)
|
||||
)
|
||||
elif sensor_details[0] == "sensors":
|
||||
# sensors will provide temp for different devices
|
||||
for sensor in client.api.data[sensor_details[0]]:
|
||||
if sensor["type"] == sensor_type:
|
||||
dev.append(
|
||||
GlancesSensor(
|
||||
client,
|
||||
name,
|
||||
sensor["label"],
|
||||
SENSOR_TYPES[sensor_type][1],
|
||||
sensor_type,
|
||||
SENSOR_TYPES[sensor_type],
|
||||
)
|
||||
)
|
||||
elif client.api.data[sensor_details[0]]:
|
||||
if sensor_details[0] == "fs":
|
||||
# fs will provide a list of disks attached
|
||||
for disk in client.api.data[sensor_details[0]]:
|
||||
dev.append(
|
||||
GlancesSensor(
|
||||
client,
|
||||
name,
|
||||
"",
|
||||
disk["mnt_point"],
|
||||
SENSOR_TYPES[sensor_type][1],
|
||||
sensor_type,
|
||||
SENSOR_TYPES[sensor_type],
|
||||
)
|
||||
)
|
||||
elif sensor_details[0] == "sensors":
|
||||
# sensors will provide temp for different devices
|
||||
for sensor in client.api.data[sensor_details[0]]:
|
||||
if sensor["type"] == sensor_type:
|
||||
dev.append(
|
||||
GlancesSensor(
|
||||
client,
|
||||
name,
|
||||
sensor["label"],
|
||||
SENSOR_TYPES[sensor_type][1],
|
||||
sensor_type,
|
||||
SENSOR_TYPES[sensor_type],
|
||||
)
|
||||
)
|
||||
elif client.api.data[sensor_details[0]]:
|
||||
dev.append(
|
||||
GlancesSensor(
|
||||
client,
|
||||
name,
|
||||
"",
|
||||
SENSOR_TYPES[sensor_type][1],
|
||||
sensor_type,
|
||||
SENSOR_TYPES[sensor_type],
|
||||
)
|
||||
)
|
||||
|
||||
async_add_entities(dev, True)
|
||||
|
||||
@ -139,107 +138,103 @@ class GlancesSensor(SensorEntity):
|
||||
if value is None:
|
||||
return
|
||||
|
||||
if value is not None:
|
||||
if self.sensor_details[0] == "fs":
|
||||
for var in value["fs"]:
|
||||
if var["mnt_point"] == self._sensor_name_prefix:
|
||||
disk = var
|
||||
break
|
||||
if self.type == "disk_use_percent":
|
||||
self._state = disk["percent"]
|
||||
elif self.type == "disk_use":
|
||||
self._state = round(disk["used"] / 1024 ** 3, 1)
|
||||
elif self.type == "disk_free":
|
||||
try:
|
||||
self._state = round(disk["free"] / 1024 ** 3, 1)
|
||||
except KeyError:
|
||||
self._state = round(
|
||||
(disk["size"] - disk["used"]) / 1024 ** 3,
|
||||
1,
|
||||
)
|
||||
elif self.type == "battery":
|
||||
for sensor in value["sensors"]:
|
||||
if sensor["type"] == "battery":
|
||||
if sensor["label"] == self._sensor_name_prefix:
|
||||
self._state = sensor["value"]
|
||||
elif self.type == "fan_speed":
|
||||
for sensor in value["sensors"]:
|
||||
if sensor["type"] == "fan_speed":
|
||||
if sensor["label"] == self._sensor_name_prefix:
|
||||
self._state = sensor["value"]
|
||||
elif self.type == "temperature_core":
|
||||
for sensor in value["sensors"]:
|
||||
if sensor["type"] == "temperature_core":
|
||||
if sensor["label"] == self._sensor_name_prefix:
|
||||
self._state = sensor["value"]
|
||||
elif self.type == "temperature_hdd":
|
||||
for sensor in value["sensors"]:
|
||||
if (
|
||||
sensor["type"] == "temperature_hdd"
|
||||
and sensor["label"] == self._sensor_name_prefix
|
||||
):
|
||||
self._state = sensor["value"]
|
||||
elif self.type == "memory_use_percent":
|
||||
self._state = value["mem"]["percent"]
|
||||
elif self.type == "memory_use":
|
||||
self._state = round(value["mem"]["used"] / 1024 ** 2, 1)
|
||||
elif self.type == "memory_free":
|
||||
self._state = round(value["mem"]["free"] / 1024 ** 2, 1)
|
||||
elif self.type == "swap_use_percent":
|
||||
self._state = value["memswap"]["percent"]
|
||||
elif self.type == "swap_use":
|
||||
self._state = round(value["memswap"]["used"] / 1024 ** 3, 1)
|
||||
elif self.type == "swap_free":
|
||||
self._state = round(value["memswap"]["free"] / 1024 ** 3, 1)
|
||||
elif self.type == "processor_load":
|
||||
# Windows systems don't provide load details
|
||||
if self.sensor_details[0] == "fs":
|
||||
for var in value["fs"]:
|
||||
if var["mnt_point"] == self._sensor_name_prefix:
|
||||
disk = var
|
||||
break
|
||||
if self.type == "disk_free":
|
||||
try:
|
||||
self._state = value["load"]["min15"]
|
||||
self._state = round(disk["free"] / 1024 ** 3, 1)
|
||||
except KeyError:
|
||||
self._state = value["cpu"]["total"]
|
||||
elif self.type == "process_running":
|
||||
self._state = value["processcount"]["running"]
|
||||
elif self.type == "process_total":
|
||||
self._state = value["processcount"]["total"]
|
||||
elif self.type == "process_thread":
|
||||
self._state = value["processcount"]["thread"]
|
||||
elif self.type == "process_sleeping":
|
||||
self._state = value["processcount"]["sleeping"]
|
||||
elif self.type == "cpu_use_percent":
|
||||
self._state = value["quicklook"]["cpu"]
|
||||
elif self.type == "docker_active":
|
||||
count = 0
|
||||
try:
|
||||
for container in value["docker"]["containers"]:
|
||||
if (
|
||||
container["Status"] == "running"
|
||||
or "Up" in container["Status"]
|
||||
):
|
||||
count += 1
|
||||
self._state = count
|
||||
except KeyError:
|
||||
self._state = count
|
||||
elif self.type == "docker_cpu_use":
|
||||
cpu_use = 0.0
|
||||
try:
|
||||
for container in value["docker"]["containers"]:
|
||||
if (
|
||||
container["Status"] == "running"
|
||||
or "Up" in container["Status"]
|
||||
):
|
||||
cpu_use += container["cpu"]["total"]
|
||||
self._state = round(cpu_use, 1)
|
||||
except KeyError:
|
||||
self._state = STATE_UNAVAILABLE
|
||||
elif self.type == "docker_memory_use":
|
||||
mem_use = 0.0
|
||||
try:
|
||||
for container in value["docker"]["containers"]:
|
||||
if (
|
||||
container["Status"] == "running"
|
||||
or "Up" in container["Status"]
|
||||
):
|
||||
mem_use += container["memory"]["usage"]
|
||||
self._state = round(mem_use / 1024 ** 2, 1)
|
||||
except KeyError:
|
||||
self._state = STATE_UNAVAILABLE
|
||||
self._state = round(
|
||||
(disk["size"] - disk["used"]) / 1024 ** 3,
|
||||
1,
|
||||
)
|
||||
elif self.type == "disk_use":
|
||||
self._state = round(disk["used"] / 1024 ** 3, 1)
|
||||
elif self.type == "disk_use_percent":
|
||||
self._state = disk["percent"]
|
||||
elif self.type == "battery":
|
||||
for sensor in value["sensors"]:
|
||||
if (
|
||||
sensor["type"] == "battery"
|
||||
and sensor["label"] == self._sensor_name_prefix
|
||||
):
|
||||
self._state = sensor["value"]
|
||||
elif self.type == "fan_speed":
|
||||
for sensor in value["sensors"]:
|
||||
if (
|
||||
sensor["type"] == "fan_speed"
|
||||
and sensor["label"] == self._sensor_name_prefix
|
||||
):
|
||||
self._state = sensor["value"]
|
||||
elif self.type == "temperature_core":
|
||||
for sensor in value["sensors"]:
|
||||
if (
|
||||
sensor["type"] == "temperature_core"
|
||||
and sensor["label"] == self._sensor_name_prefix
|
||||
):
|
||||
self._state = sensor["value"]
|
||||
elif self.type == "temperature_hdd":
|
||||
for sensor in value["sensors"]:
|
||||
if (
|
||||
sensor["type"] == "temperature_hdd"
|
||||
and sensor["label"] == self._sensor_name_prefix
|
||||
):
|
||||
self._state = sensor["value"]
|
||||
elif self.type == "memory_use_percent":
|
||||
self._state = value["mem"]["percent"]
|
||||
elif self.type == "memory_use":
|
||||
self._state = round(value["mem"]["used"] / 1024 ** 2, 1)
|
||||
elif self.type == "memory_free":
|
||||
self._state = round(value["mem"]["free"] / 1024 ** 2, 1)
|
||||
elif self.type == "swap_use_percent":
|
||||
self._state = value["memswap"]["percent"]
|
||||
elif self.type == "swap_use":
|
||||
self._state = round(value["memswap"]["used"] / 1024 ** 3, 1)
|
||||
elif self.type == "swap_free":
|
||||
self._state = round(value["memswap"]["free"] / 1024 ** 3, 1)
|
||||
elif self.type == "processor_load":
|
||||
# Windows systems don't provide load details
|
||||
try:
|
||||
self._state = value["load"]["min15"]
|
||||
except KeyError:
|
||||
self._state = value["cpu"]["total"]
|
||||
elif self.type == "process_running":
|
||||
self._state = value["processcount"]["running"]
|
||||
elif self.type == "process_total":
|
||||
self._state = value["processcount"]["total"]
|
||||
elif self.type == "process_thread":
|
||||
self._state = value["processcount"]["thread"]
|
||||
elif self.type == "process_sleeping":
|
||||
self._state = value["processcount"]["sleeping"]
|
||||
elif self.type == "cpu_use_percent":
|
||||
self._state = value["quicklook"]["cpu"]
|
||||
elif self.type == "docker_active":
|
||||
count = 0
|
||||
try:
|
||||
for container in value["docker"]["containers"]:
|
||||
if container["Status"] == "running" or "Up" in container["Status"]:
|
||||
count += 1
|
||||
self._state = count
|
||||
except KeyError:
|
||||
self._state = count
|
||||
elif self.type == "docker_cpu_use":
|
||||
cpu_use = 0.0
|
||||
try:
|
||||
for container in value["docker"]["containers"]:
|
||||
if container["Status"] == "running" or "Up" in container["Status"]:
|
||||
cpu_use += container["cpu"]["total"]
|
||||
self._state = round(cpu_use, 1)
|
||||
except KeyError:
|
||||
self._state = STATE_UNAVAILABLE
|
||||
elif self.type == "docker_memory_use":
|
||||
mem_use = 0.0
|
||||
try:
|
||||
for container in value["docker"]["containers"]:
|
||||
if container["Status"] == "running" or "Up" in container["Status"]:
|
||||
mem_use += container["memory"]["usage"]
|
||||
self._state = round(mem_use / 1024 ** 2, 1)
|
||||
except KeyError:
|
||||
self._state = STATE_UNAVAILABLE
|
||||
|
@ -1428,9 +1428,8 @@ class ModesTrait(_Trait):
|
||||
elif self.state.domain == humidifier.DOMAIN:
|
||||
if ATTR_MODE in attrs:
|
||||
mode_settings["mode"] = attrs.get(ATTR_MODE)
|
||||
elif self.state.domain == light.DOMAIN:
|
||||
if light.ATTR_EFFECT in attrs:
|
||||
mode_settings["effect"] = attrs.get(light.ATTR_EFFECT)
|
||||
elif self.state.domain == light.DOMAIN and light.ATTR_EFFECT in attrs:
|
||||
mode_settings["effect"] = attrs.get(light.ATTR_EFFECT)
|
||||
|
||||
if mode_settings:
|
||||
response["on"] = self.state.state not in (STATE_OFF, STATE_UNKNOWN)
|
||||
@ -1618,15 +1617,17 @@ class OpenCloseTrait(_Trait):
|
||||
if self.state.domain == binary_sensor.DOMAIN:
|
||||
response["queryOnlyOpenClose"] = True
|
||||
response["discreteOnlyOpenClose"] = True
|
||||
elif self.state.domain == cover.DOMAIN:
|
||||
if features & cover.SUPPORT_SET_POSITION == 0:
|
||||
response["discreteOnlyOpenClose"] = True
|
||||
elif (
|
||||
self.state.domain == cover.DOMAIN
|
||||
and features & cover.SUPPORT_SET_POSITION == 0
|
||||
):
|
||||
response["discreteOnlyOpenClose"] = True
|
||||
|
||||
if (
|
||||
features & cover.SUPPORT_OPEN == 0
|
||||
and features & cover.SUPPORT_CLOSE == 0
|
||||
):
|
||||
response["queryOnlyOpenClose"] = True
|
||||
if (
|
||||
features & cover.SUPPORT_OPEN == 0
|
||||
and features & cover.SUPPORT_CLOSE == 0
|
||||
):
|
||||
response["queryOnlyOpenClose"] = True
|
||||
|
||||
if self.state.attributes.get(ATTR_ASSUMED_STATE):
|
||||
response["commandOnlyOpenClose"] = True
|
||||
|
@ -175,9 +175,10 @@ class GoogleWifiAPI:
|
||||
sensor_value = "Online"
|
||||
else:
|
||||
sensor_value = "Offline"
|
||||
elif attr_key == ATTR_LOCAL_IP:
|
||||
if not self.raw_data["wan"]["online"]:
|
||||
sensor_value = STATE_UNKNOWN
|
||||
elif (
|
||||
attr_key == ATTR_LOCAL_IP and not self.raw_data["wan"]["online"]
|
||||
):
|
||||
sensor_value = STATE_UNKNOWN
|
||||
|
||||
self.data[attr_key] = sensor_value
|
||||
except KeyError:
|
||||
|
@ -227,9 +227,8 @@ class GPMDP(MediaPlayerEntity):
|
||||
return
|
||||
while True:
|
||||
msg = json.loads(websocket.recv())
|
||||
if "requestID" in msg:
|
||||
if msg["requestID"] == self._request_id:
|
||||
return msg
|
||||
if "requestID" in msg and msg["requestID"] == self._request_id:
|
||||
return msg
|
||||
except (
|
||||
ConnectionRefusedError,
|
||||
ConnectionResetError,
|
||||
|
Loading…
Reference in New Issue
Block a user