-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be1735a
commit 4827af5
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
"""Platform for DockerPI sensor integration.""" | ||
from homeassistant.const import TEMP_CELSIUS | ||
from homeassistant.helpers.entity import Entity | ||
|
||
|
||
import smbus | ||
|
||
DEVICE_BUS = 1 | ||
DEVICE_ADDR = 0x17 | ||
|
||
TEMP_REG = 0x01 | ||
LIGHT_REG_L = 0x02 | ||
LIGHT_REG_H = 0x03 | ||
STATUS_REG = 0x04 | ||
ON_BOARD_TEMP_REG = 0x05 | ||
ON_BOARD_HUMIDITY_REG = 0x06 | ||
ON_BOARD_SENSOR_ERROR = 0x07 | ||
BMP280_TEMP_REG = 0x08 | ||
BMP280_PRESSURE_REG_L = 0x09 | ||
BMP280_PRESSURE_REG_M = 0x0A | ||
BMP280_PRESSURE_REG_H = 0x0B | ||
BMP280_STATUS = 0x0C | ||
HUMAN_DETECT = 0x0D | ||
|
||
bus = smbus.SMBus(DEVICE_BUS) | ||
|
||
aReceiveBuf = [] | ||
|
||
aReceiveBuf.append(0x00) | ||
|
||
for i in range(TEMP_REG,HUMAN_DETECT + 1): | ||
aReceiveBuf.append(bus.read_byte_data(DEVICE_ADDR, i)) | ||
|
||
|
||
|
||
def setup_platform(hass, config, add_entities, discovery_info=None): | ||
"""Set up the sensor platform.""" | ||
add_entities([DockerPI_Sensor()]) | ||
|
||
|
||
class DockerPI_Sensor(Entity): | ||
"""Representation of a Sensor.""" | ||
|
||
def __init__(self): | ||
"""Initialize the sensor.""" | ||
self._state = None | ||
|
||
@property | ||
def name(self): | ||
"""Return the name of the sensor.""" | ||
return 'Temperature' | ||
|
||
@property | ||
def state(self): | ||
"""Return the state of the sensor.""" | ||
return self._state | ||
|
||
@property | ||
def unit_of_measurement(self): | ||
"""Return the unit of measurement.""" | ||
return TEMP_CELSIUS | ||
|
||
def update(self): | ||
"""Fetch new state data for the sensor. | ||
This is the only method that should fetch new data for Home Assistant. | ||
""" | ||
self._state = aReceiveBuf[ON_BOARD_TEMP_REG]) |