Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to home assistant 0.100.1 sensor #2

Closed
wants to merge 13 commits into from
107 changes: 0 additions & 107 deletions .gitignore

This file was deleted.

5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# ruuvi_hass
RuuviTag sensor for hass.io

Copy ruuvi-hass.py to <config folder>/custom_components/sensor/ (e.g. /home/homeassistant/.homeassistant/custom_components/sensor/ruuvi-hass.py)
Copy ruuvi-hass.py, manifest.json and ____init.py_____ to <config folder>/custom_components/ruuvi-hass/ (e.g. /home/homeassistant/.homeassistant/custom_components/ruuvi-hass.py)


The configuration.yaml has to be edited like this
```
Expand All @@ -14,3 +15,5 @@ sensor:
mac: 'MA:CA:DD:RE:SS:01'
name: 'bathroom'
```
Todo:
- Add more sensors (acceleration)
1 change: 1 addition & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""The ruuvitag component."""
10 changes: 10 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"domain": "ruuvi-hass",
"name": "RuuviTag integration for Home Assistant",
"documentation": "https://github.com/salleq/ruuvi_hass",
"requirements": ["ruuvitag-sensor"],
"dependencies": [],
"config_flow": false,
"codeowners": ["@JonasR", "@salleq", "@PieterGit"],
"homeassistant": "0.100.1"
}
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruuvitag-sensor
23 changes: 16 additions & 7 deletions ruuvi-hass.py → sensor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Platform for RuuviTag sensor integration."""

import datetime
import logging

Expand All @@ -11,6 +13,9 @@
CONF_FORCE_UPDATE, CONF_MONITORED_CONDITIONS, CONF_NAME, CONF_MAC
)

from ruuvitag_sensor.ruuvi import RuuviTagSensor


REQUIREMENTS = ['ruuvitag_sensor']

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -42,10 +47,11 @@
vol.Optional(CONF_ADAPTER, default=DEFAULT_ADAPTER): cv.string,
})

#def setup_platform(hass, config, add_entities, discovery_info=None):
# """Set up the sensor platform."""
# add_entities([RuuviTagSensor()])

def setup_platform(hass, config, add_devices, discovery_info=None):
from ruuvitag_sensor.ruuvi import RuuviTagSensor

mac_addresses = config.get(CONF_MAC)
if not isinstance(mac_addresses, list):
mac_addresses = [mac_addresses]
Expand All @@ -57,7 +63,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
for condition in config.get(CONF_MONITORED_CONDITIONS):
prefix = config.get(CONF_NAME, mac_address)
name = "{} {}".format(prefix, condition)

_LOGGER.info("setup_platform for RuuviTag %s" % name)
devs.append(RuuviSensor(
probe, config.get(CONF_MAC), condition, name
))
Expand Down Expand Up @@ -86,6 +92,7 @@ def poll(self):


class RuuviSensor(Entity):
"""Representation of the RuuviTag Sensor."""
def __init__(self, poller, mac_address, sensor_type, name):
self.poller = poller
self._name = name
Expand All @@ -96,20 +103,22 @@ def __init__(self, poller, mac_address, sensor_type, name):

@property
def name(self):
"""Return the name of the sensor."""
return self._name

@property
def state(self):
"""Return the unit of measurement."""
return self._state

@property
def unit_of_measurement(self):
"""Return the unit of measurement."""
return SENSOR_TYPES[self.sensor_type][1]

def update(self):
"""Fetch new state data for the sensor.
This is the only method that should fetch new data for Home Assistant.
"""
self.poller.poll()

self._state = self.poller.conditions.get(self.mac_address, {}).get(self.sensor_type)