mirror of
https://github.com/home-assistant/core.git
synced 2025-08-11 06:20:01 +00:00
.github
config
docs
homeassistant
components
alarm_control_panel
automation
binary_sensor
camera
device_tracker
frontend
garage_door
light
lock
media_player
mqtt
notify
rollershutter
scene
sensor
__init__.py
apcupsd.py
arduino.py
arest.py
bitcoin.py
bloomsky.py
command_line.py
cpuspeed.py
demo.py
deutsche_bahn.py
dht.py
dweet.py
ecobee.py
efergy.py
eliqonline.py
forecast.py
glances.py
gtfs.py
isy994.py
loopenergy.py
mfi.py
modbus.py
mqtt.py
mysensors.py
nest.py
netatmo.py
neurio_energy.py
nzbget.py
onewire.py
openweathermap.py
rest.py
rfxtrx.py
sabnzbd.py
speedtest.py
steam_online.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
yr.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
ecobee.py
feedreader.py
graphite.py
group.py
history.py
http.py
ifttt.py
influxdb.py
input_boolean.py
input_select.py
input_slider.py
insteon_hub.py
introduction.py
isy994.py
keyboard.py
logbook.py
logger.py
modbus.py
mqtt_eventstream.py
mysensors.py
nest.py
proximity.py
recorder.py
rfxtrx.py
rpi_gpio.py
script.py
scsgate.py
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
startup
util
__init__.py
__main__.py
bootstrap.py
config.py
const.py
core.py
exceptions.py
loader.py
remote.py
script
tests
.coveragerc
.gitignore
.gitmodules
.travis.yml
CONTRIBUTING.md
Dockerfile
LICENSE
MANIFEST.in
README.rst
pylintrc
requirements_all.txt
requirements_test.txt
setup.cfg
setup.py
tox.ini
65 lines
2.1 KiB
Python
65 lines
2.1 KiB
Python
"""
|
|
Support for getting temperature from TEMPer devices.
|
|
|
|
For more details about this platform, please refer to the documentation at
|
|
https://home-assistant.io/components/sensor.temper/
|
|
"""
|
|
import logging
|
|
|
|
from homeassistant.const import CONF_NAME, DEVICE_DEFAULT_NAME, TEMP_FAHRENHEIT
|
|
from homeassistant.helpers.entity import Entity
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
REQUIREMENTS = ['https://github.com/rkabadi/temper-python/archive/'
|
|
'3dbdaf2d87b8db9a3cd6e5585fc704537dd2d09b.zip'
|
|
'#temperusb==1.2.3']
|
|
|
|
|
|
# pylint: disable=unused-argument
|
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|
"""Setup the Temper sensors."""
|
|
from temperusb.temper import TemperHandler
|
|
|
|
temp_unit = hass.config.temperature_unit
|
|
name = config.get(CONF_NAME, DEVICE_DEFAULT_NAME)
|
|
temper_devices = TemperHandler().get_devices()
|
|
add_devices_callback([TemperSensor(dev, temp_unit, name + '_' + str(idx))
|
|
for idx, dev in enumerate(temper_devices)])
|
|
|
|
|
|
class TemperSensor(Entity):
|
|
"""Representation of a Temper temperature sensor."""
|
|
|
|
def __init__(self, temper_device, temp_unit, name):
|
|
"""Initialize the sensor."""
|
|
self.temper_device = temper_device
|
|
self.temp_unit = temp_unit
|
|
self.current_value = None
|
|
self._name = name
|
|
|
|
@property
|
|
def name(self):
|
|
"""Return the name of the temperature sensor."""
|
|
return self._name
|
|
|
|
@property
|
|
def state(self):
|
|
"""Return the state of the entity."""
|
|
return self.current_value
|
|
|
|
@property
|
|
def unit_of_measurement(self):
|
|
"""Return the unit of measurement of this entity, if any."""
|
|
return self.temp_unit
|
|
|
|
def update(self):
|
|
"""Retrieve latest state."""
|
|
try:
|
|
format_str = ('fahrenheit' if self.temp_unit == TEMP_FAHRENHEIT
|
|
else 'celsius')
|
|
self.current_value = self.temper_device.get_temperature(format_str)
|
|
except IOError:
|
|
_LOGGER.error('Failed to get temperature due to insufficient '
|
|
'permissions. Try running with "sudo"')
|