mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
Reduce functools.partial with ServiceCall.hass in energyzero (#133134)
This commit is contained in:
parent
684667e8e7
commit
f816a0667c
@ -83,12 +83,12 @@ def __serialize_prices(prices: Electricity | Gas) -> ServiceResponse:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def __get_coordinator(
|
def __get_coordinator(call: ServiceCall) -> EnergyZeroDataUpdateCoordinator:
|
||||||
hass: HomeAssistant, call: ServiceCall
|
|
||||||
) -> EnergyZeroDataUpdateCoordinator:
|
|
||||||
"""Get the coordinator from the entry."""
|
"""Get the coordinator from the entry."""
|
||||||
entry_id: str = call.data[ATTR_CONFIG_ENTRY]
|
entry_id: str = call.data[ATTR_CONFIG_ENTRY]
|
||||||
entry: EnergyZeroConfigEntry | None = hass.config_entries.async_get_entry(entry_id)
|
entry: EnergyZeroConfigEntry | None = call.hass.config_entries.async_get_entry(
|
||||||
|
entry_id
|
||||||
|
)
|
||||||
|
|
||||||
if not entry:
|
if not entry:
|
||||||
raise ServiceValidationError(
|
raise ServiceValidationError(
|
||||||
@ -113,10 +113,9 @@ def __get_coordinator(
|
|||||||
async def __get_prices(
|
async def __get_prices(
|
||||||
call: ServiceCall,
|
call: ServiceCall,
|
||||||
*,
|
*,
|
||||||
hass: HomeAssistant,
|
|
||||||
price_type: PriceType,
|
price_type: PriceType,
|
||||||
) -> ServiceResponse:
|
) -> ServiceResponse:
|
||||||
coordinator = __get_coordinator(hass, call)
|
coordinator = __get_coordinator(call)
|
||||||
|
|
||||||
start = __get_date(call.data.get(ATTR_START))
|
start = __get_date(call.data.get(ATTR_START))
|
||||||
end = __get_date(call.data.get(ATTR_END))
|
end = __get_date(call.data.get(ATTR_END))
|
||||||
@ -151,14 +150,14 @@ def async_setup_services(hass: HomeAssistant) -> None:
|
|||||||
hass.services.async_register(
|
hass.services.async_register(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
GAS_SERVICE_NAME,
|
GAS_SERVICE_NAME,
|
||||||
partial(__get_prices, hass=hass, price_type=PriceType.GAS),
|
partial(__get_prices, price_type=PriceType.GAS),
|
||||||
schema=SERVICE_SCHEMA,
|
schema=SERVICE_SCHEMA,
|
||||||
supports_response=SupportsResponse.ONLY,
|
supports_response=SupportsResponse.ONLY,
|
||||||
)
|
)
|
||||||
hass.services.async_register(
|
hass.services.async_register(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
ENERGY_SERVICE_NAME,
|
ENERGY_SERVICE_NAME,
|
||||||
partial(__get_prices, hass=hass, price_type=PriceType.ENERGY),
|
partial(__get_prices, price_type=PriceType.ENERGY),
|
||||||
schema=SERVICE_SCHEMA,
|
schema=SERVICE_SCHEMA,
|
||||||
supports_response=SupportsResponse.ONLY,
|
supports_response=SupportsResponse.ONLY,
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user