Add switch entity to Zimi integration (#144236)

* Import switch.py

* Alignment to light.py

* Use default switch attributes

* Update homeassistant/components/zimi/switch.py

---------

Co-authored-by: Josef Zweck <josef@zweck.dev>
This commit is contained in:
markhannon 2025-05-07 16:34:32 +10:00 committed by GitHub
parent 946172d530
commit 6e7f57383a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 57 additions and 1 deletions

View File

@ -16,7 +16,7 @@ from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
from .const import DOMAIN
from .helpers import async_connect_to_controller
PLATFORMS = [Platform.LIGHT]
PLATFORMS = [Platform.LIGHT, Platform.SWITCH]
_LOGGER = logging.getLogger(__name__)

View File

@ -0,0 +1,56 @@
"""Switch platform for zcc integration."""
from __future__ import annotations
import logging
from typing import Any
from homeassistant.components.switch import SwitchEntity
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from . import ZimiConfigEntry
from .entity import ZimiEntity
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ZimiConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up the Zimi Switch platform."""
api = config_entry.runtime_data
outlets = [ZimiSwitch(device, api) for device in api.outlets]
async_add_entities(outlets)
class ZimiSwitch(ZimiEntity, SwitchEntity):
"""Representation of an Zimi Switch."""
@property
def is_on(self) -> bool:
"""Return true if switch is on."""
return self._device.is_on
async def async_turn_on(self, **kwargs: Any) -> None:
"""Instruct the switch to turn on."""
_LOGGER.debug(
"Sending turn_on() for %s in %s", self._device.name, self._device.room
)
await self._device.turn_on()
async def async_turn_off(self, **kwargs: Any) -> None:
"""Instruct the switch to turn off."""
_LOGGER.debug(
"Sending turn_off() for %s in %s", self._device.name, self._device.room
)
await self._device.turn_off()