mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Address HomeConnect late review (#74308)
* Small changes as requested in PR 58768 * Fix ValueError message formatting * Use f-string * Remove None as return type of _get_appliance_by_device_id Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
da11cef29a
commit
2464322dc5
@ -103,15 +103,14 @@ PLATFORMS = [Platform.BINARY_SENSOR, Platform.LIGHT, Platform.SENSOR, Platform.S
|
|||||||
|
|
||||||
def _get_appliance_by_device_id(
|
def _get_appliance_by_device_id(
|
||||||
hass: HomeAssistant, device_id: str
|
hass: HomeAssistant, device_id: str
|
||||||
) -> api.HomeConnectDevice | None:
|
) -> api.HomeConnectDevice:
|
||||||
"""Return a Home Connect appliance instance given an device_id."""
|
"""Return a Home Connect appliance instance given an device_id."""
|
||||||
for hc_api in hass.data[DOMAIN].values():
|
for hc_api in hass.data[DOMAIN].values():
|
||||||
for dev_dict in hc_api.devices:
|
for dev_dict in hc_api.devices:
|
||||||
device = dev_dict[CONF_DEVICE]
|
device = dev_dict[CONF_DEVICE]
|
||||||
if device.device_id == device_id:
|
if device.device_id == device_id:
|
||||||
return device.appliance
|
return device.appliance
|
||||||
_LOGGER.error("Appliance for device id %s not found", device_id)
|
raise ValueError(f"Appliance for device id {device_id} not found")
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
@ -148,18 +147,14 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
}
|
}
|
||||||
|
|
||||||
appliance = _get_appliance_by_device_id(hass, device_id)
|
appliance = _get_appliance_by_device_id(hass, device_id)
|
||||||
if appliance is not None:
|
await hass.async_add_executor_job(getattr(appliance, method), program, options)
|
||||||
await hass.async_add_executor_job(
|
|
||||||
getattr(appliance, method), program, options
|
|
||||||
)
|
|
||||||
|
|
||||||
async def _async_service_command(call, command):
|
async def _async_service_command(call, command):
|
||||||
"""Execute calls to services executing a command."""
|
"""Execute calls to services executing a command."""
|
||||||
device_id = call.data[ATTR_DEVICE_ID]
|
device_id = call.data[ATTR_DEVICE_ID]
|
||||||
|
|
||||||
appliance = _get_appliance_by_device_id(hass, device_id)
|
appliance = _get_appliance_by_device_id(hass, device_id)
|
||||||
if appliance is not None:
|
await hass.async_add_executor_job(appliance.execute_command, command)
|
||||||
await hass.async_add_executor_job(appliance.execute_command, command)
|
|
||||||
|
|
||||||
async def _async_service_key_value(call, method):
|
async def _async_service_key_value(call, method):
|
||||||
"""Execute calls to services taking a key and value."""
|
"""Execute calls to services taking a key and value."""
|
||||||
@ -169,20 +164,19 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
device_id = call.data[ATTR_DEVICE_ID]
|
device_id = call.data[ATTR_DEVICE_ID]
|
||||||
|
|
||||||
appliance = _get_appliance_by_device_id(hass, device_id)
|
appliance = _get_appliance_by_device_id(hass, device_id)
|
||||||
if appliance is not None:
|
if unit is not None:
|
||||||
if unit is not None:
|
await hass.async_add_executor_job(
|
||||||
await hass.async_add_executor_job(
|
getattr(appliance, method),
|
||||||
getattr(appliance, method),
|
key,
|
||||||
key,
|
value,
|
||||||
value,
|
unit,
|
||||||
unit,
|
)
|
||||||
)
|
else:
|
||||||
else:
|
await hass.async_add_executor_job(
|
||||||
await hass.async_add_executor_job(
|
getattr(appliance, method),
|
||||||
getattr(appliance, method),
|
key,
|
||||||
key,
|
value,
|
||||||
value,
|
)
|
||||||
)
|
|
||||||
|
|
||||||
async def async_service_option_active(call):
|
async def async_service_option_active(call):
|
||||||
"""Service for setting an option for an active program."""
|
"""Service for setting an option for an active program."""
|
||||||
|
@ -113,7 +113,6 @@ class HomeConnectDevice:
|
|||||||
"""Initialize the device class."""
|
"""Initialize the device class."""
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
self.appliance = appliance
|
self.appliance = appliance
|
||||||
self.entities = []
|
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
"""Fetch the info needed to initialize the device."""
|
"""Fetch the info needed to initialize the device."""
|
||||||
|
@ -20,7 +20,6 @@ class HomeConnectEntity(Entity):
|
|||||||
self.device = device
|
self.device = device
|
||||||
self.desc = desc
|
self.desc = desc
|
||||||
self._name = f"{self.device.appliance.name} {desc}"
|
self._name = f"{self.device.appliance.name} {desc}"
|
||||||
self.device.entities.append(self)
|
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""Register callbacks."""
|
"""Register callbacks."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user