Reduce functools.partial with ServiceCall.hass in easyenergy (#133133)
parent
4a5e47d2f0
commit
a131497e1f
|
@ -86,12 +86,12 @@ def __serialize_prices(prices: list[dict[str, float | datetime]]) -> ServiceResp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def __get_coordinator(
|
def __get_coordinator(call: ServiceCall) -> EasyEnergyDataUpdateCoordinator:
|
||||||
hass: HomeAssistant, call: ServiceCall
|
|
||||||
) -> EasyEnergyDataUpdateCoordinator:
|
|
||||||
"""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: EasyEnergyConfigEntry | None = hass.config_entries.async_get_entry(entry_id)
|
entry: EasyEnergyConfigEntry | None = call.hass.config_entries.async_get_entry(
|
||||||
|
entry_id
|
||||||
|
)
|
||||||
|
|
||||||
if not entry:
|
if not entry:
|
||||||
raise ServiceValidationError(
|
raise ServiceValidationError(
|
||||||
|
@ -116,11 +116,10 @@ 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:
|
||||||
"""Get prices from easyEnergy."""
|
"""Get prices from easyEnergy."""
|
||||||
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))
|
||||||
|
@ -156,21 +155,21 @@ 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_USAGE_SERVICE_NAME,
|
ENERGY_USAGE_SERVICE_NAME,
|
||||||
partial(__get_prices, hass=hass, price_type=PriceType.ENERGY_USAGE),
|
partial(__get_prices, price_type=PriceType.ENERGY_USAGE),
|
||||||
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_RETURN_SERVICE_NAME,
|
ENERGY_RETURN_SERVICE_NAME,
|
||||||
partial(__get_prices, hass=hass, price_type=PriceType.ENERGY_RETURN),
|
partial(__get_prices, price_type=PriceType.ENERGY_RETURN),
|
||||||
schema=SERVICE_SCHEMA,
|
schema=SERVICE_SCHEMA,
|
||||||
supports_response=SupportsResponse.ONLY,
|
supports_response=SupportsResponse.ONLY,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue