1 """Support for PCA 301 smart switch."""
3 from __future__
import annotations
9 from serial
import SerialException
17 _LOGGER = logging.getLogger(__name__)
19 DEFAULT_NAME =
"PCA 301"
25 add_entities: AddEntitiesCallback,
26 discovery_info: DiscoveryInfoType |
None =
None,
28 """Set up the PCA switch platform."""
30 if discovery_info
is None:
33 serial_device = discovery_info[
"device"]
36 pca = pypca.PCA(serial_device)
39 entities = [
SmartPlugSwitch(pca, device)
for device
in pca.get_devices()]
42 except SerialException
as exc:
43 _LOGGER.warning(
"Unable to open serial port: %s", exc)
46 hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, pca.close)
52 """Representation of a PCA Smart Plug switch."""
55 """Initialize the switch."""
64 """Return the name of the Smart Plug, if any."""
65 return self.
_name_name
69 """Return if switch is available."""
74 """Return true if switch is on."""
78 """Turn the switch on."""
82 """Turn the switch off."""
86 """Update the PCA switch's state."""
93 _LOGGER.warning(
"Could not read state for %s: %s", self.
namenamename, ex)
None turn_off(self, **Any kwargs)
def __init__(self, pca, device_id)
None turn_on(self, **Any kwargs)
str|UndefinedType|None name(self)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
str|float get_state(dict[str, float] data, str key)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)