1
0
mirror of https://github.com/home-assistant/core.git synced 2025-08-22 03:40:02 +00:00
Files
.github
config
docs
homeassistant
components
alarm_control_panel
automation
binary_sensor
camera
climate
cover
device_tracker
fan
frontend
garage_door
hvac
light
lock
media_player
mqtt
notify
recorder
rollershutter
scene
sensor
__init__.py
apcupsd.py
arduino.py
arest.py
bitcoin.py
bloomsky.py
coinmarketcap.py
command_line.py
cpuspeed.py
demo.py
deutsche_bahn.py
dht.py
dte_energy_bridge.py
dweet.py
ecobee.py
efergy.py
eliqonline.py
enocean.py
envisalink.py
fastdotcom.py
fitbit.py
fixer.py
forecast.py
fritzbox_callmonitor.py
glances.py
google_travel_time.py
gpsd.py
gtfs.py
homematic.py
hp_ilo.py
imap.py
isy994.py
lastfm.py
linux_battery.py
loopenergy.py
mfi.py
mhz19.py
modbus.py
mold_indicator.py
mqtt.py
mqtt_room.py
mysensors.py
nest.py
netatmo.py
neurio_energy.py
nzbget.py
octoprint.py
ohmconnect.py
onewire.py
openexchangerates.py
openweathermap.py
pi_hole.py
plex.py
rest.py
rfxtrx.py
sabnzbd.py
serial_pm.py
snmp.py
speedtest.py
steam_online.py
supervisord.py
swiss_hydrological_data.py
swiss_public_transport.py
systemmonitor.py
tcp.py
tellduslive.py
tellstick.py
temper.py
template.py
thinkingcleaner.py
time_date.py
torque.py
transmission.py
twitch.py
uber.py
vera.py
verisure.py
wink.py
worldclock.py
wunderground.py
xbox_live.py
yr.py
yweather.py
zigbee.py
zwave.py
switch
thermostat
__init__.py
alexa.py
apcupsd.py
api.py
arduino.py
bloomsky.py
browser.py
configurator.py
conversation.py
demo.py
device_sun_light_trigger.py
discovery.py
downloader.py
dweet.py
ecobee.py
emulated_hue.py
enocean.py
envisalink.py
feedreader.py
foursquare.py
graphite.py
group.py
hdmi_cec.py
history.py
homematic.py
http.py
ifttt.py
influxdb.py
input_boolean.py
input_select.py
input_slider.py
insteon_hub.py
introduction.py
isy994.py
joaoapps_join.py
keyboard.py
knx.py
lirc.py
logbook.py
logentries.py
logger.py
modbus.py
mqtt_eventstream.py
mysensors.py
nest.py
netatmo.py
octoprint.py
panel_custom.py
panel_iframe.py
persistent_notification.py
pilight.py
proximity.py
qwikswitch.py
rfxtrx.py
rpi_gpio.py
script.py
scsgate.py
services.yaml
shell_command.py
splunk.py
statsd.py
sun.py
tellduslive.py
tellstick.py
updater.py
upnp.py
vera.py
verisure.py
weblink.py
wemo.py
wink.py
zeroconf.py
zigbee.py
zone.py
zwave.py
helpers
scripts
util
__init__.py
__main__.py
bootstrap.py
config.py
const.py
core.py
exceptions.py
loader.py
remote.py
script
tests
virtualization
.coveragerc
.dockerignore
.gitignore
.gitmodules
.travis.yml
CONTRIBUTING.md
Dockerfile
LICENSE
MANIFEST.in
README.rst
pylintrc
requirements_all.txt
requirements_docs.txt
requirements_test.txt
setup.cfg
setup.py
tox.ini
core/homeassistant/components/sensor/demo.py
2016-04-19 20:30:44 -07:00

57 lines
1.5 KiB
Python

"""
Demo platform that has a couple of fake sensors.
For more details about this platform, please refer to the documentation
https://home-assistant.io/components/demo/
"""
from homeassistant.const import ATTR_BATTERY_LEVEL, TEMP_CELSIUS
from homeassistant.helpers.entity import Entity
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Demo sensors."""
add_devices([
DemoSensor('Outside Temperature', 15.6, TEMP_CELSIUS, 12),
DemoSensor('Outside Humidity', 54, '%', None),
])
class DemoSensor(Entity):
"""Representation of a Demo sensor."""
def __init__(self, name, state, unit_of_measurement, battery):
"""Initialize the sensor."""
self._name = name
self._state = state
self._unit_of_measurement = unit_of_measurement
self._battery = battery
@property
def should_poll(self):
"""No polling needed for a demo sensor."""
return False
@property
def name(self):
"""Return the name of the sensor."""
return self._name
@property
def state(self):
"""Return the state of the sensor."""
return self._state
@property
def unit_of_measurement(self):
"""Return the unit this state is expressed in."""
return self._unit_of_measurement
@property
def device_state_attributes(self):
"""Return the state attributes."""
if self._battery:
return {
ATTR_BATTERY_LEVEL: self._battery,
}