Repository: home-assistant/core
File: homeassistant/components/vodafone_station/switch.py (Python)

Code before:
        for switch_desc in SWITCHES
        if switch_desc.key in wifi[WIFI_DATA]
    )


class VodafoneSwitchEntity(CoordinatorEntity[VodafoneStationRouter], SwitchEntity):
    """Switch device."""

    _attr_has_entity_name = True
    entity_description: VodafoneStationEntityDescription

    def __init__(
        self,
        coordinator: VodafoneStationRouter,
        description: VodafoneStationEntityDescription,
    ) -> None:
        """Initialize switch device."""
        super().__init__(coordinator)
        self.entity_description = description
        self._attr_device_info = coordinator.device_info
        self._attr_name = coordinator.data.wifi[WIFI_DATA][description.key]["ssid"]
        self._attr_unique_id = f"{coordinator.serial_number}_{description.key}"

    async def async_turn_on(self, **kwargs: Any) -> None:
        """Turn the switch on."""
        await self.coordinator.api.set_wifi_status(
            True, self.entity_description.typology, self.entity_description.band
        )

    async def async_turn_off(self, **kwargs: Any) -> None:
        """Turn the switch off."""
        await self.coordinator.api.set_wifi_status(
            False, self.entity_description.typology, self.entity_description.band
        )

    @property
    def is_on(self) -> bool:
        """Return True if switch is on."""
        return bool(
            self.coordinator.data.wifi[WIFI_DATA][self.entity_description.key]["on"]
        )


Review comment (suggestion):
missing exception handling to comply with `actions-exceptions` status in the IQS

Code after:
async def async_setup_entry(
    hass: HomeAssistant,
    entry: VodafoneConfigEntry,
    async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
    """Set up Vodafone Station switches based on a config entry."""

    coordinator = entry.runtime_data

    wifi = coordinator.data.wifi

    async_add_entities(
        VodafoneSwitchEntity(coordinator, switch_desc)
        for switch_desc in SWITCHES
        if switch_desc.key in wifi[WIFI_DATA]
    )


class VodafoneSwitchEntity(CoordinatorEntity[VodafoneStationRouter], SwitchEntity):
    """Switch device."""

    _attr_has_entity_name = True
    entity_description: VodafoneStationEntityDescription

    def __init__(
        self,
        coordinator: VodafoneStationRouter,
        description: VodafoneStationEntityDescription,
    ) -> None:
        """Initialize switch device."""
        super().__init__(coordinator)
        self.entity_description = description
        self._attr_device_info = coordinator.device_info
        self._attr_unique_id = f"{coordinator.serial_number}_{description.key}"

    async def _set_wifi_status(self, status: bool) -> None:
        """Set the wifi status."""
        try:
            await self.coordinator.api.set_wifi_status(
                status, self.entity_description.typology, self.entity_description.band
            )
        except CannotAuthenticate as err:
            self.coordinator.config_entry.async_start_reauth(self.hass)
            raise HomeAssistantError(
                translation_domain=DOMAIN,
                translation_key="cannot_authenticate",
                translation_placeholders={"error": repr(err)},
            ) from err
        except (
            CannotConnect,
            AlreadyLogged,