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

Code before:

    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_name = coordinator.data.wifi[WIFI_DATA][description.key]["ssid"]
        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,
            GenericLoginError,
            GenericResponseError,
            JSONDecodeError,
        ) as err:
            self.coordinator.last_update_success = False
            raise HomeAssistantError(
                translation_domain=DOMAIN,

Review comment (suggestion):
I am wondering if having the SSID here makes sense. Would it make sense to also add like "Guest network" or something? I think seeing a switch that just has the SSID name is one of those "if you know you know" things as you wouldn't directly see what it could do without trying out

Code after:
) -> 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,
            GenericLoginError,
            GenericResponseError,
            JSONDecodeError,
        ) as err: