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

Add support for wind, battery, radio signals for Netatmo sensor #2351

Merged
merged 5 commits into from
Jun 22, 2016
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 93 additions & 8 deletions homeassistant/components/sensor/netatmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,31 @@
from homeassistant.util import Throttle
from homeassistant.loader import get_component

# Fix for pylint too many statements error
# pylint: disable=too-many-statements
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't add this here at the top of the module, but local where the problem is. Put it on the next row directly after the docstring in the update method, near row 109. The disable statement has scope, so it's best to disable as little as possible, and it also makes it easier to see why it was needed.

The update method could be refactored to avoid the disable. It might be out of scope for this PR, but I would do a nested dict lookup and have a function that checks if data value is above inner dict value.


DEPENDENCIES = ["netatmo"]

_LOGGER = logging.getLogger(__name__)

SENSOR_TYPES = {
'temperature': ['Temperature', TEMP_CELSIUS, 'mdi:thermometer'],
'co2': ['CO2', 'ppm', 'mdi:cloud'],
'pressure': ['Pressure', 'mbar', 'mdi:gauge'],
'noise': ['Noise', 'dB', 'mdi:volume-high'],
'humidity': ['Humidity', '%', 'mdi:water-percent'],
'rain': ['Rain', 'mm', 'mdi:weather-rainy'],
'sum_rain_1': ['sum_rain_1', 'mm', 'mdi:weather-rainy'],
'sum_rain_24': ['sum_rain_24', 'mm', 'mdi:weather-rainy'],
'temperature': ['Temperature', TEMP_CELSIUS, 'mdi:thermometer'],
'co2': ['CO2', 'ppm', 'mdi:cloud'],
'pressure': ['Pressure', 'mbar', 'mdi:gauge'],
'noise': ['Noise', 'dB', 'mdi:volume-high'],
'humidity': ['Humidity', '%', 'mdi:water-percent'],
'rain': ['Rain', 'mm', 'mdi:weather-rainy'],
'sum_rain_1': ['sum_rain_1', 'mm', 'mdi:weather-rainy'],
'sum_rain_24': ['sum_rain_24', 'mm', 'mdi:weather-rainy'],
'battery_vp': ['Battery', '', 'mdi:battery'],
'min_temp': ['Min Temp.', TEMP_CELSIUS, 'mdi:thermometer'],
'max_temp': ['Max Temp.', TEMP_CELSIUS, 'mdi:thermometer'],
'WindAngle': ['Angle', '', 'mdi:compass'],
'WindStrength': ['Strength', 'km/h', 'mdi:weather-windy'],
'GustAngle': ['Gust Angle', '', 'mdi:compass'],
'GustStrength': ['Gust Strength', 'km/h', 'mdi:weather-windy'],
'rf_status': ['Radio', '', 'mdi:signal'],
'wifi_status': ['Wifi', '', 'mdi:wifi']
}

CONF_STATION = 'station'
Expand Down Expand Up @@ -118,6 +130,79 @@ def update(self):
self._state = data['CO2']
elif self.type == 'pressure':
self._state = round(data['Pressure'], 1)
elif self.type == 'battery_vp':
if data['battery_vp'] >= 5500:
self._state = "Full"
elif data['battery_vp'] >= 5100:
self._state = "High"
elif data['battery_vp'] >= 4600:
self._state = "Medium"
elif data['battery_vp'] >= 4100:
self._state = "Low"
elif data['battery_vp'] < 4100:
self._state = "Very Low"
elif self.type == 'min_temp':
self._state = data['min_temp']
elif self.type == 'max_temp':
self._state = data['max_temp']
elif self.type == 'WindAngle':
if data['WindAngle'] >= 330:
self._state = "North (%d\xb0)" % data['WindAngle']
elif data['WindAngle'] >= 300:
self._state = "North-West (%d\xb0)" % data['WindAngle']
elif data['WindAngle'] >= 240:
self._state = "West (%d\xb0)" % data['WindAngle']
elif data['WindAngle'] >= 210:
self._state = "South-West (%d\xb0)" % data['WindAngle']
elif data['WindAngle'] >= 150:
self._state = "South (%d\xb0)" % data['WindAngle']
elif data['WindAngle'] >= 120:
self._state = "South-East (%d\xb0)" % data['WindAngle']
elif data['WindAngle'] >= 60:
self._state = "East (%d\xb0)" % data['WindAngle']
elif data['WindAngle'] >= 30:
self._state = "North-East (%d\xb0)" % data['WindAngle']
elif data['WindAngle'] >= 0:
self._state = "North (%d\xb0)" % data['WindAngle']
elif self.type == 'WindStrength':
self._state = data['WindStrength']
elif self.type == 'GustAngle':
if data['GustAngle'] >= 330:
self._state = "North (%d\xb0)" % data['GustAngle']
elif data['GustAngle'] >= 300:
self._state = "North-West (%d\xb0)" % data['GustAngle']
elif data['GustAngle'] >= 240:
self._state = "West (%d\xb0)" % data['GustAngle']
elif data['GustAngle'] >= 210:
self._state = "South-West (%d\xb0)" % data['GustAngle']
elif data['GustAngle'] >= 150:
self._state = "South (%d\xb0)" % data['GustAngle']
elif data['GustAngle'] >= 120:
self._state = "South-East (%d\xb0)" % data['GustAngle']
elif data['GustAngle'] >= 60:
self._state = "East (%d\xb0)" % data['GustAngle']
elif data['GustAngle'] >= 30:
self._state = "North-East (%d\xb0)" % data['GustAngle']
elif data['GustAngle'] >= 0:
self._state = "North (%d\xb0)" % data['GustAngle']
elif self.type == 'GustStrength':
self._state = data['GustStrength']
elif self.type == 'rf_status':
if data['rf_status'] >= 90:
self._state = "Low"
elif data['rf_status'] >= 76:
self._state = "Medium"
elif data['rf_status'] >= 60:
self._state = "High"
elif data['rf_status'] <= 59:
self._state = "Full"
elif self.type == 'wifi_status':
if data['wifi_status'] >= 86:
self._state = "Bad"
elif data['wifi_status'] >= 71:
self._state = "Middle"
elif data['wifi_status'] <= 70:
self._state = "Good"


class NetAtmoData(object):
Expand Down