mirror of
https://github.com/home-assistant/core.git
synced 2025-08-12 06:50:00 +00:00
.github
docs
homeassistant
components
alarm_control_panel
alexa
automation
binary_sensor
calendar
camera
climate
cloud
config
counter
cover
device_tracker
emulated_hue
fan
frontend
google_assistant
group
http
image_processing
light
lock
mailbox
media_player
mqtt
notify
persistent_notification
recorder
remember_the_milk
remote
scene
sensor
__init__.py
abode.py
airvisual.py
alarmdecoder.py
amcrest.py
android_ip_webcam.py
apcupsd.py
api_streams.py
arduino.py
arest.py
arlo.py
arwn.py
bbox.py
bh1750.py
bitcoin.py
blink.py
blockchain.py
bloomsky.py
bme280.py
bom.py
broadlink.py
buienradar.py
cert_expiry.py
citybikes.py
coinmarketcap.py
comed_hourly_pricing.py
comfoconnect.py
command_line.py
cpuspeed.py
crimereports.py
cups.py
currencylayer.py
darksky.py
deluge.py
demo.py
deutsche_bahn.py
dht.py
dnsip.py
dovado.py
dsmr.py
dte_energy_bridge.py
dublin_bus_transport.py
dwd_weather_warnings.py
dweet.py
dyson.py
ebox.py
ecobee.py
eddystone_temperature.py
efergy.py
eight_sleep.py
eliqonline.py
emoncms.py
enocean.py
envirophat.py
envisalink.py
etherscan.py
fail2ban.py
fastdotcom.py
fedex.py
fido.py
file.py
fitbit.py
fixer.py
fritzbox_callmonitor.py
fritzbox_netmonitor.py
geizhals.py
geo_rss_events.py
gitter.py
glances.py
google_travel_time.py
google_wifi.py
gpsd.py
gtfs.py
haveibeenpwned.py
hddtemp.py
history_stats.py
homematic.py
hp_ilo.py
htu21d.py
hydroquebec.py
imap.py
imap_email_content.py
influxdb.py
ios.py
irish_rail_transport.py
isy994.py
juicenet.py
kira.py
knx.py
kwb.py
lacrosse.py
lastfm.py
linux_battery.py
london_air.py
london_underground.py
loopenergy.py
luftdaten.py
lyft.py
metoffice.py
mfi.py
mhz19.py
miflora.py
min_max.py
modbus.py
modem_callerid.py
mold_indicator.py
moon.py
mopar.py
mqtt.py
mqtt_room.py
mvglive.py
mysensors.py
nederlandse_spoorwegen.py
nest.py
netatmo.py
netdata.py
neurio_energy.py
nut.py
nzbget.py
octoprint.py
ohmconnect.py
onewire.py
openevse.py
openexchangerates.py
openhardwaremonitor.py
opensky.py
openweathermap.py
otp.py
pi_hole.py
pilight.py
plex.py
pocketcasts.py
pushbullet.py
pvoutput.py
pyload.py
qnap.py
radarr.py
raincloud.py
random.py
rest.py
rflink.py
rfxtrx.py
ring.py
ripple.py
sabnzbd.py
scrape.py
season.py
sensehat.py
serial.py
serial_pm.py
shodan.py
skybeacon.py
skybell.py
sleepiq.py
sma.py
snmp.py
sonarr.py
speedtest.py
statistics.py
steam_online.py
supervisord.py
swiss_hydrological_data.py
swiss_public_transport.py
synologydsm.py
systemmonitor.py
sytadin.py
tado.py
tank_utility.py
tcp.py
ted5000.py
tellduslive.py
tellstick.py
temper.py
template.py
tesla.py
thethingsnetwork.py
thinkingcleaner.py
tibber.py
time_date.py
toon.py
torque.py
tradfri.py
transmission.py
travisci.py
twitch.py
uber.py
uk_transport.py
upnp.py
ups.py
uptime.py
usps.py
vasttrafik.py
vera.py
verisure.py
version.py
volvooncall.py
vultr.py
waqi.py
whois.py
wink.py
worldclock.py
worldtidesinfo.py
worxlandroid.py
wsdot.py
wunderground.py
xbox_live.py
xiaomi_aqara.py
yahoo_finance.py
yr.py
yweather.py
zabbix.py
zamg.py
zha.py
zigbee.py
zoneminder.py
zwave.py
switch
telegram_bot
timer
tts
vacuum
weather
wink
zha
zwave
__init__.py
abode.py
alarmdecoder.py
alert.py
amcrest.py
android_ip_webcam.py
apcupsd.py
api.py
apple_tv.py
arduino.py
arlo.py
asterisk_mbox.py
axis.py
bbb_gpio.py
blink.py
bloomsky.py
browser.py
comfoconnect.py
configurator.py
conversation.py
datadog.py
demo.py
device_sun_light_trigger.py
dialogflow.py
digital_ocean.py
discovery.py
doorbird.py
downloader.py
duckdns.py
dweet.py
dyson.py
ecobee.py
eight_sleep.py
emoncms_history.py
enocean.py
envisalink.py
feedreader.py
ffmpeg.py
foursquare.py
gc100.py
google.py
google_domains.py
graphite.py
hassio.py
hdmi_cec.py
history.py
history_graph.py
homematic.py
ifttt.py
influxdb.py
input_boolean.py
input_datetime.py
input_number.py
input_select.py
input_text.py
insteon_local.py
insteon_plm.py
intent_script.py
introduction.py
ios.py
isy994.py
joaoapps_join.py
juicenet.py
keyboard.py
keyboard_remote.py
kira.py
knx.py
lametric.py
linode.py
lirc.py
litejet.py
logbook.py
logentries.py
logger.py
lutron.py
lutron_caseta.py
mailgun.py
map.py
maxcube.py
media_extractor.py
microsoft_face.py
mochad.py
modbus.py
mqtt_eventstream.py
mqtt_statestream.py
mycroft.py
mysensors.py
namecheapdns.py
neato.py
nest.py
netatmo.py
no_ip.py
nuimo_controller.py
octoprint.py
panel_custom.py
panel_iframe.py
pilight.py
plant.py
prometheus.py
proximity.py
python_script.py
qwikswitch.py
raincloud.py
raspihats.py
rest_command.py
rflink.py
rfxtrx.py
ring.py
rpi_gpio.py
rpi_pfio.py
rss_feed_template.py
satel_integra.py
script.py
scsgate.py
services.yaml
shell_command.py
shiftr.py
shopping_list.py
skybell.py
sleepiq.py
snips.py
spc.py
splunk.py
statsd.py
sun.py
tado.py
tellduslive.py
tellstick.py
tesla.py
thethingsnetwork.py
thingspeak.py
toon.py
tradfri.py
twilio.py
updater.py
upnp.py
usps.py
velbus.py
velux.py
vera.py
verisure.py
volvooncall.py
vultr.py
wake_on_lan.py
weblink.py
websocket_api.py
wemo.py
xiaomi_aqara.py
zabbix.py
zeroconf.py
zigbee.py
zone.py
zoneminder.py
helpers
scripts
util
__init__.py
__main__.py
bootstrap.py
config.py
const.py
core.py
exceptions.py
loader.py
monkey_patch.py
package_constraints.txt
remote.py
setup.py
script
tests
virtualization
.coveragerc
.dockerignore
.gitignore
.gitmodules
.hound.yml
.ignore
.travis.yml
CLA.md
CODEOWNERS
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile
LICENSE.md
MANIFEST.in
README.rst
pylintrc
requirements_all.txt
requirements_docs.txt
requirements_test.txt
requirements_test_all.txt
setup.cfg
setup.py
tox.ini
112 lines
3.3 KiB
Python
112 lines
3.3 KiB
Python
"""
|
|
Support for KNX/IP sensors.
|
|
|
|
For more details about this platform, please refer to the documentation at
|
|
https://home-assistant.io/components/sensor.knx/
|
|
"""
|
|
import asyncio
|
|
import voluptuous as vol
|
|
|
|
from homeassistant.components.knx import DATA_KNX, ATTR_DISCOVER_DEVICES
|
|
from homeassistant.helpers.entity import Entity
|
|
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
|
from homeassistant.const import CONF_NAME
|
|
from homeassistant.core import callback
|
|
import homeassistant.helpers.config_validation as cv
|
|
|
|
CONF_ADDRESS = 'address'
|
|
CONF_TYPE = 'type'
|
|
|
|
DEFAULT_NAME = 'KNX Sensor'
|
|
DEPENDENCIES = ['knx']
|
|
|
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|
vol.Required(CONF_ADDRESS): cv.string,
|
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
|
vol.Optional(CONF_TYPE): cv.string,
|
|
})
|
|
|
|
|
|
@asyncio.coroutine
|
|
def async_setup_platform(hass, config, async_add_devices,
|
|
discovery_info=None):
|
|
"""Set up sensor(s) for KNX platform."""
|
|
if DATA_KNX not in hass.data \
|
|
or not hass.data[DATA_KNX].initialized:
|
|
return False
|
|
|
|
if discovery_info is not None:
|
|
async_add_devices_discovery(hass, discovery_info, async_add_devices)
|
|
else:
|
|
async_add_devices_config(hass, config, async_add_devices)
|
|
|
|
return True
|
|
|
|
|
|
@callback
|
|
def async_add_devices_discovery(hass, discovery_info, async_add_devices):
|
|
"""Set up sensors for KNX platform configured via xknx.yaml."""
|
|
entities = []
|
|
for device_name in discovery_info[ATTR_DISCOVER_DEVICES]:
|
|
device = hass.data[DATA_KNX].xknx.devices[device_name]
|
|
entities.append(KNXSensor(hass, device))
|
|
async_add_devices(entities)
|
|
|
|
|
|
@callback
|
|
def async_add_devices_config(hass, config, async_add_devices):
|
|
"""Set up sensor for KNX platform configured within plattform."""
|
|
import xknx
|
|
sensor = xknx.devices.Sensor(
|
|
hass.data[DATA_KNX].xknx,
|
|
name=config.get(CONF_NAME),
|
|
group_address=config.get(CONF_ADDRESS),
|
|
value_type=config.get(CONF_TYPE))
|
|
hass.data[DATA_KNX].xknx.devices.add(sensor)
|
|
async_add_devices([KNXSensor(hass, sensor)])
|
|
|
|
|
|
class KNXSensor(Entity):
|
|
"""Representation of a KNX sensor."""
|
|
|
|
def __init__(self, hass, device):
|
|
"""Initialization of KNXSensor."""
|
|
self.device = device
|
|
self.hass = hass
|
|
self.async_register_callbacks()
|
|
|
|
@callback
|
|
def async_register_callbacks(self):
|
|
"""Register callbacks to update hass after device was changed."""
|
|
@asyncio.coroutine
|
|
def after_update_callback(device):
|
|
"""Callback after device was updated."""
|
|
# pylint: disable=unused-argument
|
|
yield from self.async_update_ha_state()
|
|
self.device.register_device_updated_cb(after_update_callback)
|
|
|
|
@property
|
|
def name(self):
|
|
"""Return the name of the KNX device."""
|
|
return self.device.name
|
|
|
|
@property
|
|
def should_poll(self):
|
|
"""No polling needed within KNX."""
|
|
return False
|
|
|
|
@property
|
|
def state(self):
|
|
"""Return the state of the sensor."""
|
|
return self.device.resolve_state()
|
|
|
|
@property
|
|
def unit_of_measurement(self):
|
|
"""Return the unit this state is expressed in."""
|
|
return self.device.unit_of_measurement()
|
|
|
|
@property
|
|
def device_state_attributes(self):
|
|
"""Return the state attributes."""
|
|
return None
|