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