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(
|
||||
hass: HomeAssistant, call: ServiceCall
|
||||
) -> EasyEnergyDataUpdateCoordinator:
|
||||
def __get_coordinator(call: ServiceCall) -> EasyEnergyDataUpdateCoordinator:
|
||||
"""Get the coordinator from the 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:
|
||||
raise ServiceValidationError(
|
||||
|
@ -116,11 +116,10 @@ def __get_coordinator(
|
|||
async def __get_prices(
|
||||
call: ServiceCall,
|
||||
*,
|
||||
hass: HomeAssistant,
|
||||
price_type: PriceType,
|
||||
) -> ServiceResponse:
|
||||
"""Get prices from easyEnergy."""
|
||||
coordinator = __get_coordinator(hass, call)
|
||||
coordinator = __get_coordinator(call)
|
||||
|
||||
start = __get_date(call.data.get(ATTR_START))
|
||||
end = __get_date(call.data.get(ATTR_END))
|
||||
|
@ -156,21 +155,21 @@ def async_setup_services(hass: HomeAssistant) -> None:
|
|||
hass.services.async_register(
|
||||
DOMAIN,
|
||||
GAS_SERVICE_NAME,
|
||||
partial(__get_prices, hass=hass, price_type=PriceType.GAS),
|
||||
partial(__get_prices, price_type=PriceType.GAS),
|
||||
schema=SERVICE_SCHEMA,
|
||||
supports_response=SupportsResponse.ONLY,
|
||||
)
|
||||
hass.services.async_register(
|
||||
DOMAIN,
|
||||
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,
|
||||
supports_response=SupportsResponse.ONLY,
|
||||
)
|
||||
hass.services.async_register(
|
||||
DOMAIN,
|
||||
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,
|
||||
supports_response=SupportsResponse.ONLY,
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue