mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Improve lists in integrations [P-Q] (#113236)
This commit is contained in:
parent
dc7eaee917
commit
9f19e7339d
@ -66,18 +66,15 @@ class PicnicCart(TodoListEntity, CoordinatorEntity[PicnicUpdateCoordinator]):
|
||||
|
||||
_LOGGER.debug(self.coordinator.data["cart_data"]["items"])
|
||||
|
||||
items = []
|
||||
for item in self.coordinator.data["cart_data"]["items"]:
|
||||
for article in item["items"]:
|
||||
items.append(
|
||||
return [
|
||||
TodoItem(
|
||||
summary=f"{article['name']} ({article['unit_quantity']})",
|
||||
uid=f"{item['id']}-{article['id']}",
|
||||
status=TodoItemStatus.NEEDS_ACTION, # We set 'NEEDS_ACTION' so they count as state
|
||||
)
|
||||
)
|
||||
|
||||
return items
|
||||
for item in self.coordinator.data["cart_data"]["items"]
|
||||
for article in item["items"]
|
||||
]
|
||||
|
||||
async def async_create_todo_item(self, item: TodoItem) -> None:
|
||||
"""Add item to shopping cart."""
|
||||
|
@ -293,10 +293,7 @@ def generate_plex_uri(server_id, media_id, params=None):
|
||||
|
||||
def root_payload(hass, is_internal, platform=None):
|
||||
"""Return root payload for Plex."""
|
||||
children = []
|
||||
|
||||
for server_id in get_plex_data(hass)[SERVERS]:
|
||||
children.append(
|
||||
children = [
|
||||
browse_media(
|
||||
hass,
|
||||
is_internal,
|
||||
@ -304,7 +301,8 @@ def root_payload(hass, is_internal, platform=None):
|
||||
generate_plex_uri(server_id, ""),
|
||||
platform=platform,
|
||||
)
|
||||
)
|
||||
for server_id in get_plex_data(hass)[SERVERS]
|
||||
]
|
||||
|
||||
if len(children) == 1:
|
||||
return children[0]
|
||||
|
@ -57,12 +57,14 @@ async def async_setup_entry(
|
||||
"""Set up Plex sensor from a config entry."""
|
||||
server_id = config_entry.data[CONF_SERVER_IDENTIFIER]
|
||||
plexserver = get_plex_server(hass, server_id)
|
||||
sensors = [PlexSensor(hass, plexserver)]
|
||||
sensors: list[SensorEntity] = [PlexSensor(hass, plexserver)]
|
||||
|
||||
def create_library_sensors():
|
||||
"""Create Plex library sensors with sync calls."""
|
||||
for library in plexserver.library.sections():
|
||||
sensors.append(PlexLibrarySectionSensor(hass, plexserver, library))
|
||||
sensors.extend(
|
||||
PlexLibrarySectionSensor(hass, plexserver, library)
|
||||
for library in plexserver.library.sections()
|
||||
)
|
||||
|
||||
await hass.async_add_executor_job(create_library_sensors)
|
||||
async_add_entities(sensors)
|
||||
|
@ -76,16 +76,13 @@ async def async_setup_entry(
|
||||
config_entry.entry_id
|
||||
]
|
||||
|
||||
entities: list[PlugwiseNumberEntity] = []
|
||||
for device_id, device in coordinator.data.devices.items():
|
||||
for description in NUMBER_TYPES:
|
||||
if description.key in device:
|
||||
entities.append(
|
||||
async_add_entities(
|
||||
PlugwiseNumberEntity(coordinator, device_id, description)
|
||||
for device_id, device in coordinator.data.devices.items()
|
||||
for description in NUMBER_TYPES
|
||||
if description.key in device
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class PlugwiseNumberEntity(PlugwiseEntity, NumberEntity):
|
||||
"""Representation of a Plugwise number."""
|
||||
|
@ -68,16 +68,13 @@ async def async_setup_entry(
|
||||
config_entry.entry_id
|
||||
]
|
||||
|
||||
entities: list[PlugwiseSelectEntity] = []
|
||||
for device_id, device in coordinator.data.devices.items():
|
||||
for description in SELECT_TYPES:
|
||||
if description.options_key in device:
|
||||
entities.append(
|
||||
async_add_entities(
|
||||
PlugwiseSelectEntity(coordinator, device_id, description)
|
||||
for device_id, device in coordinator.data.devices.items()
|
||||
for description in SELECT_TYPES
|
||||
if description.options_key in device
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class PlugwiseSelectEntity(PlugwiseEntity, SelectEntity):
|
||||
"""Represent Smile selector."""
|
||||
|
@ -29,7 +29,6 @@ async def async_setup_entry(
|
||||
"""Set up the binary sensors from a config entry."""
|
||||
board_api = hass.data[DOMAIN][config_entry.entry_id]
|
||||
input_count = config_entry.data["input_count"]
|
||||
binary_sensors = []
|
||||
|
||||
async def async_update_data():
|
||||
"""Fetch data from API endpoint of board."""
|
||||
@ -45,17 +44,15 @@ async def async_setup_entry(
|
||||
)
|
||||
await coordinator.async_refresh()
|
||||
|
||||
for i in range(1, int(input_count) + 1):
|
||||
binary_sensors.append(
|
||||
async_add_entities(
|
||||
ProgettihwswBinarySensor(
|
||||
coordinator,
|
||||
f"Input #{i}",
|
||||
setup_input(board_api, i),
|
||||
)
|
||||
for i in range(1, int(input_count) + 1)
|
||||
)
|
||||
|
||||
async_add_entities(binary_sensors)
|
||||
|
||||
|
||||
class ProgettihwswBinarySensor(CoordinatorEntity, BinarySensorEntity):
|
||||
"""Represent a binary sensor."""
|
||||
|
@ -30,7 +30,6 @@ async def async_setup_entry(
|
||||
"""Set up the switches from a config entry."""
|
||||
board_api = hass.data[DOMAIN][config_entry.entry_id]
|
||||
relay_count = config_entry.data["relay_count"]
|
||||
switches = []
|
||||
|
||||
async def async_update_data():
|
||||
"""Fetch data from API endpoint of board."""
|
||||
@ -46,17 +45,15 @@ async def async_setup_entry(
|
||||
)
|
||||
await coordinator.async_refresh()
|
||||
|
||||
for i in range(1, int(relay_count) + 1):
|
||||
switches.append(
|
||||
async_add_entities(
|
||||
ProgettihwswSwitch(
|
||||
coordinator,
|
||||
f"Relay #{i}",
|
||||
setup_switch(board_api, i, config_entry.data[f"relay_{str(i)}"]),
|
||||
)
|
||||
for i in range(1, int(relay_count) + 1)
|
||||
)
|
||||
|
||||
async_add_entities(switches)
|
||||
|
||||
|
||||
class ProgettihwswSwitch(CoordinatorEntity, SwitchEntity):
|
||||
"""Represent a switch entity."""
|
||||
|
@ -154,8 +154,10 @@ async def async_setup_entry(
|
||||
coordinator: ElecPricesDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
sensors = [ElecPriceSensor(coordinator, SENSOR_TYPES[0], entry.unique_id)]
|
||||
if coordinator.api.using_private_api:
|
||||
for sensor_desc in SENSOR_TYPES[1:]:
|
||||
sensors.append(ElecPriceSensor(coordinator, sensor_desc, entry.unique_id))
|
||||
sensors.extend(
|
||||
ElecPriceSensor(coordinator, sensor_desc, entry.unique_id)
|
||||
for sensor_desc in SENSOR_TYPES[1:]
|
||||
)
|
||||
async_add_entities(sensors)
|
||||
|
||||
|
||||
|
@ -83,14 +83,14 @@ async def async_setup_entry(
|
||||
"""Add QNAP QSW binary sensors from a config_entry."""
|
||||
coordinator: QswDataCoordinator = hass.data[DOMAIN][entry.entry_id][QSW_COORD_DATA]
|
||||
|
||||
entities: list[QswBinarySensor] = []
|
||||
|
||||
for description in BINARY_SENSOR_TYPES:
|
||||
entities: list[QswBinarySensor] = [
|
||||
QswBinarySensor(coordinator, description, entry)
|
||||
for description in BINARY_SENSOR_TYPES
|
||||
if (
|
||||
description.key in coordinator.data
|
||||
and description.subkey in coordinator.data[description.key]
|
||||
):
|
||||
entities.append(QswBinarySensor(coordinator, description, entry))
|
||||
)
|
||||
]
|
||||
|
||||
for description in LACP_PORT_BINARY_SENSOR_TYPES:
|
||||
if (
|
||||
|
@ -288,14 +288,14 @@ async def async_setup_entry(
|
||||
"""Add QNAP QSW sensors from a config_entry."""
|
||||
coordinator: QswDataCoordinator = hass.data[DOMAIN][entry.entry_id][QSW_COORD_DATA]
|
||||
|
||||
entities: list[QswSensor] = []
|
||||
|
||||
for description in SENSOR_TYPES:
|
||||
entities: list[QswSensor] = [
|
||||
QswSensor(coordinator, description, entry)
|
||||
for description in SENSOR_TYPES
|
||||
if (
|
||||
description.key in coordinator.data
|
||||
and description.subkey in coordinator.data[description.key]
|
||||
):
|
||||
entities.append(QswSensor(coordinator, description, entry))
|
||||
)
|
||||
]
|
||||
|
||||
for description in LACP_PORT_SENSOR_TYPES:
|
||||
if (
|
||||
|
Loading…
x
Reference in New Issue
Block a user