Skip to content

Commit

Permalink
Port PyMySensors from external to requirements.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed Jul 20, 2015
1 parent a390624 commit 4edf538
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
[submodule "homeassistant/external/nzbclients"]
path = homeassistant/external/nzbclients
url = https://github.com/jamespcole/home-assistant-nzb-clients.git
[submodule "homeassistant/external/pymysensors"]
path = homeassistant/external/pymysensors
url = https://github.com/theolind/pymysensors
[submodule "homeassistant/components/frontend/www_static/home-assistant-polymer"]
path = homeassistant/components/frontend/www_static/home-assistant-polymer
url = https://github.com/balloob/home-assistant-polymer.git
28 changes: 15 additions & 13 deletions homeassistant/components/sensor/mysensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
"""
import logging

# pylint: disable=no-name-in-module, import-error
import homeassistant.external.pymysensors.mysensors.mysensors as mysensors
import homeassistant.external.pymysensors.mysensors.const as const
from homeassistant.helpers.entity import Entity

from homeassistant.const import (
Expand All @@ -39,12 +36,16 @@
ATTR_CHILD_ID = "child_id"

_LOGGER = logging.getLogger(__name__)
REQUIREMENTS = ['pyserial>=2.7']
REQUIREMENTS = ['https://github.com/theolind/pymysensors/archive/master.zip'
'#egg=pymysensors-0.1']


def setup_platform(hass, config, add_devices, discovery_info=None):
""" Setup the mysensors platform. """

import mysensors.mysensors as mysensors
import mysensors.const as const

devices = {} # keep track of devices added to HA
# Just assume celcius means that the user wants metric for now.
# It may make more sense to make this a global config option in the future.
Expand All @@ -69,7 +70,7 @@ def sensor_update(update_type, nid):
name = '{} {}.{}'.format(sensor.sketch_name, nid, child.id)
node[child_id][value_type] = \
MySensorsNodeValue(
nid, child_id, name, value_type, is_metric)
nid, child_id, name, value_type, is_metric, const)
new_devices.append(node[child_id][value_type])
else:
node[child_id][value_type].update_sensor(
Expand Down Expand Up @@ -102,15 +103,16 @@ def sensor_update(update_type, nid):

class MySensorsNodeValue(Entity):
""" Represents the value of a MySensors child node. """
# pylint: disable=too-many-arguments
def __init__(self, node_id, child_id, name, value_type, metric):
# pylint: disable=too-many-arguments, too-many-instance-attributes
def __init__(self, node_id, child_id, name, value_type, metric, const):
self._name = name
self.node_id = node_id
self.child_id = child_id
self.battery_level = 0
self.value_type = value_type
self.metric = metric
self._value = ''
self.const = const

@property
def should_poll(self):
Expand All @@ -130,11 +132,11 @@ def state(self):
@property
def unit_of_measurement(self):
""" Unit of measurement of this entity. """
if self.value_type == const.SetReq.V_TEMP:
if self.value_type == self.const.SetReq.V_TEMP:
return TEMP_CELCIUS if self.metric else TEMP_FAHRENHEIT
elif self.value_type == const.SetReq.V_HUM or \
self.value_type == const.SetReq.V_DIMMER or \
self.value_type == const.SetReq.V_LIGHT_LEVEL:
elif self.value_type == self.const.SetReq.V_HUM or \
self.value_type == self.const.SetReq.V_DIMMER or \
self.value_type == self.const.SetReq.V_LIGHT_LEVEL:
return '%'
return None

Expand All @@ -150,8 +152,8 @@ def state_attributes(self):
def update_sensor(self, value, battery_level):
""" Update a sensor with the latest value from the controller. """
_LOGGER.info("%s value = %s", self._name, value)
if self.value_type == const.SetReq.V_TRIPPED or \
self.value_type == const.SetReq.V_ARMED:
if self.value_type == self.const.SetReq.V_TRIPPED or \
self.value_type == self.const.SetReq.V_ARMED:
self._value = STATE_ON if int(value) == 1 else STATE_OFF
else:
self._value = value
Expand Down
1 change: 0 additions & 1 deletion homeassistant/external/pymysensors
Submodule pymysensors deleted from cd5ef8
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ python-forecastio>=1.3.3
# Firmata Bindings (*.arduino)
PyMata==2.07a

# Mysensors serial gateway
pyserial>=2.7
# Mysensors
https://github.com/theolind/pymysensors/archive/master.zip#egg=pymysensors-0.1

0 comments on commit 4edf538

Please sign in to comment.