1 """Support for Pilight sensors."""
3 from __future__
import annotations
7 import voluptuous
as vol
10 PLATFORM_SCHEMA
as SENSOR_PLATFORM_SCHEMA,
21 _LOGGER = logging.getLogger(__name__)
23 CONF_VARIABLE =
"variable"
25 DEFAULT_NAME =
"Pilight Sensor"
26 PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA.extend(
28 vol.Required(CONF_VARIABLE): cv.string,
29 vol.Required(CONF_PAYLOAD): vol.Schema(dict),
30 vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
31 vol.Optional(CONF_UNIT_OF_MEASUREMENT): cv.string,
39 add_entities: AddEntitiesCallback,
40 discovery_info: DiscoveryInfoType |
None =
None,
42 """Set up Pilight Sensor."""
47 name=config.get(CONF_NAME),
48 variable=config.get(CONF_VARIABLE),
49 payload=config.get(CONF_PAYLOAD),
50 unit_of_measurement=config.get(CONF_UNIT_OF_MEASUREMENT),
57 """Representation of a sensor that can be updated using Pilight."""
59 _attr_should_poll =
False
61 def __init__(self, hass, name, variable, payload, unit_of_measurement):
62 """Initialize the sensor."""
74 """Return the name of the sensor."""
75 return self.
_name_name
79 """Return the unit this state is expressed in."""
84 """Return the state of the entity."""
88 """Handle received code by the pilight-daemon.
90 If the code matches the defined payload
91 of this sensor the sensor state is changed accordingly.
96 if self.
_payload_payload.items() <= call.data.items():
98 value = call.data[self.
_variable_variable]
103 "No variable %s in received code data %s",
def _handle_code(self, call)
def native_unit_of_measurement(self)
def __init__(self, hass, name, variable, payload, unit_of_measurement)
None schedule_update_ha_state(self, bool force_refresh=False)
def add_entities(account, async_add_entities, tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)