Skip to content

Commit

Permalink
Create sensor.py
Browse files Browse the repository at this point in the history
  • Loading branch information
icornish72 authored Feb 22, 2021
1 parent be1735a commit 4827af5
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions sensor.py
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])

0 comments on commit 4827af5

Please sign in to comment.