1 """Support for switches that can be controlled using the RaspyRFM rc module."""
3 from __future__
import annotations
5 from raspyrfm_client
import RaspyRFMClient
6 from raspyrfm_client.device_implementations.controlunit.actions
import Action
7 from raspyrfm_client.device_implementations.controlunit.controlunit_constants
import (
10 from raspyrfm_client.device_implementations.gateway.manufacturer.gateway_constants
import (
13 from raspyrfm_client.device_implementations.manufacturer_constants
import Manufacturer
14 import voluptuous
as vol
17 PLATFORM_SCHEMA
as SWITCH_PLATFORM_SCHEMA,
32 CONF_GATEWAY_MANUFACTURER =
"gateway_manufacturer"
33 CONF_GATEWAY_MODEL =
"gateway_model"
34 CONF_CONTROLUNIT_MANUFACTURER =
"controlunit_manufacturer"
35 CONF_CONTROLUNIT_MODEL =
"controlunit_model"
36 CONF_CHANNEL_CONFIG =
"channel_config"
37 DEFAULT_HOST =
"127.0.0.1"
40 PLATFORM_SCHEMA = SWITCH_PLATFORM_SCHEMA.extend(
42 vol.Optional(CONF_HOST, default=DEFAULT_HOST): cv.string,
43 vol.Optional(CONF_PORT): cv.port,
44 vol.Optional(CONF_GATEWAY_MANUFACTURER): cv.string,
45 vol.Optional(CONF_GATEWAY_MODEL): cv.string,
46 vol.Required(CONF_SWITCHES): vol.Schema(
49 vol.Optional(CONF_NAME, default=DEVICE_DEFAULT_NAME): cv.string,
50 vol.Required(CONF_CONTROLUNIT_MANUFACTURER): cv.string,
51 vol.Required(CONF_CONTROLUNIT_MODEL): cv.string,
52 vol.Required(CONF_CHANNEL_CONFIG): {cv.string: cv.match_all},
57 extra=vol.ALLOW_EXTRA,
64 add_entities: AddEntitiesCallback,
65 discovery_info: DiscoveryInfoType |
None =
None,
67 """Set up the RaspyRFM switch."""
69 gateway_manufacturer = config.get(
70 CONF_GATEWAY_MANUFACTURER, Manufacturer.SEEGEL_SYSTEME.value
72 gateway_model = config.get(CONF_GATEWAY_MODEL, GatewayModel.RASPYRFM.value)
73 host = config[CONF_HOST]
74 port = config.get(CONF_PORT)
75 switches = config[CONF_SWITCHES]
77 raspyrfm_client = RaspyRFMClient()
78 gateway = raspyrfm_client.get_gateway(
79 Manufacturer(gateway_manufacturer), GatewayModel(gateway_model), host, port
82 for switch
in switches:
83 name = switch[CONF_NAME]
84 controlunit_manufacturer = switch[CONF_CONTROLUNIT_MANUFACTURER]
85 controlunit_model = switch[CONF_CONTROLUNIT_MODEL]
86 channel_config = switch[CONF_CHANNEL_CONFIG]
88 controlunit = raspyrfm_client.get_controlunit(
89 Manufacturer(controlunit_manufacturer), ControlUnitModel(controlunit_model)
92 controlunit.set_channel_config(**channel_config)
94 switch =
RaspyRFMSwitch(raspyrfm_client, name, gateway, controlunit)
95 switch_entities.append(switch)
101 """Representation of a RaspyRFM switch."""
103 _attr_should_poll =
False
105 def __init__(self, raspyrfm_client, name: str, gateway, controlunit) ->
None:
106 """Initialize the switch."""
117 """Return the name of the device if any."""
118 return self.
_name_name
122 """Return True when the current state cannot be queried."""
127 """Return true if switch is on."""
131 """Turn the switch on."""
138 """Turn the switch off."""
140 if Action.OFF
in self.
_controlunit_controlunit.get_supported_actions():
def turn_on(self, **kwargs)
None __init__(self, raspyrfm_client, str name, gateway, controlunit)
def turn_off(self, **kwargs)
None schedule_update_ha_state(self, bool force_refresh=False)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)