-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathsensor.py
More file actions
31 lines (21 loc) · 901 Bytes
/
Copy pathsensor.py
File metadata and controls
31 lines (21 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import logging
from homeassistant.components.sensor import SensorEntity
from homeassistant.const import CONF_UNIT_OF_MEASUREMENT
from homeassistant.core import HomeAssistant
from . import PythonEntity, compile_script
_LOGGER = logging.getLogger(__name__)
async def async_setup_platform(
hass: HomeAssistant, config, async_add_entities, discovery_info=None
) -> None:
if code := await hass.async_add_executor_job(compile_script, hass, config):
async_add_entities([PythonSensor(code, config)], True)
class PythonSensor(SensorEntity, PythonEntity):
def __init__(self, code, config: dict):
PythonEntity.__init__(self, code, config)
self._attr_native_unit_of_measurement = config.get(CONF_UNIT_OF_MEASUREMENT)
@property
def state(self):
return super().state
@state.setter
def state(self, value):
self._attr_native_value = value