From 2464322dc5693b1a0dc979d5da4b4e4acf1fb573 Mon Sep 17 00:00:00 2001 From: Frank <46161394+BraveChicken1@users.noreply.github.com> Date: Sat, 2 Jul 2022 16:06:07 +0200 Subject: [PATCH] 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 --- .../components/home_connect/__init__.py | 40 ++++++++----------- homeassistant/components/home_connect/api.py | 1 - .../components/home_connect/entity.py | 1 - 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/homeassistant/components/home_connect/__init__.py b/homeassistant/components/home_connect/__init__.py index f57c7aeb8af..50e51b4ae1e 100644 --- a/homeassistant/components/home_connect/__init__.py +++ b/homeassistant/components/home_connect/__init__.py @@ -103,15 +103,14 @@ PLATFORMS = [Platform.BINARY_SENSOR, Platform.LIGHT, Platform.SENSOR, Platform.S def _get_appliance_by_device_id( hass: HomeAssistant, device_id: str -) -> api.HomeConnectDevice | None: +) -> api.HomeConnectDevice: """Return a Home Connect appliance instance given an device_id.""" for hc_api in hass.data[DOMAIN].values(): for dev_dict in hc_api.devices: device = dev_dict[CONF_DEVICE] if device.device_id == device_id: return device.appliance - _LOGGER.error("Appliance for device id %s not found", device_id) - return None + raise ValueError(f"Appliance for device id {device_id} not found") 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) - 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): """Execute calls to services executing a command.""" device_id = call.data[ATTR_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): """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] appliance = _get_appliance_by_device_id(hass, device_id) - if appliance is not None: - if unit is not None: - await hass.async_add_executor_job( - getattr(appliance, method), - key, - value, - unit, - ) - else: - await hass.async_add_executor_job( - getattr(appliance, method), - key, - value, - ) + if unit is not None: + await hass.async_add_executor_job( + getattr(appliance, method), + key, + value, + unit, + ) + else: + await hass.async_add_executor_job( + getattr(appliance, method), + key, + value, + ) async def async_service_option_active(call): """Service for setting an option for an active program.""" diff --git a/homeassistant/components/home_connect/api.py b/homeassistant/components/home_connect/api.py index 00d759b47d5..f3c98e618b8 100644 --- a/homeassistant/components/home_connect/api.py +++ b/homeassistant/components/home_connect/api.py @@ -113,7 +113,6 @@ class HomeConnectDevice: """Initialize the device class.""" self.hass = hass self.appliance = appliance - self.entities = [] def initialize(self): """Fetch the info needed to initialize the device.""" diff --git a/homeassistant/components/home_connect/entity.py b/homeassistant/components/home_connect/entity.py index 60a0c3974cd..b27988f997d 100644 --- a/homeassistant/components/home_connect/entity.py +++ b/homeassistant/components/home_connect/entity.py @@ -20,7 +20,6 @@ class HomeConnectEntity(Entity): self.device = device self.desc = desc self._name = f"{self.device.appliance.name} {desc}" - self.device.entities.append(self) async def async_added_to_hass(self): """Register callbacks."""