diff --git a/homeassistant/components/garage_door/wink.py b/homeassistant/components/garage_door/wink.py index aa714a790caac5fee88be0e573e1672808994557..b32b20dde0a809be7f97a0a85be016be314c94e1 100644 --- a/homeassistant/components/garage_door/wink.py +++ b/homeassistant/components/garage_door/wink.py @@ -11,7 +11,7 @@ import logging from homeassistant.components.garage_door import GarageDoorDevice from homeassistant.const import CONF_ACCESS_TOKEN -REQUIREMENTS = ['python-wink==0.5.0'] +REQUIREMENTS = ['python-wink==0.6.0'] def setup_platform(hass, config, add_devices, discovery_info=None): diff --git a/homeassistant/components/light/wink.py b/homeassistant/components/light/wink.py index 6b7bb1afcec74ecc4581a49bd9d61673191925dd..2fed8904762d569a6c0dbe449e63d059b1a1d6dc 100644 --- a/homeassistant/components/light/wink.py +++ b/homeassistant/components/light/wink.py @@ -11,7 +11,7 @@ import logging from homeassistant.components.light import ATTR_BRIGHTNESS, Light from homeassistant.const import CONF_ACCESS_TOKEN -REQUIREMENTS = ['python-wink==0.5.0'] +REQUIREMENTS = ['python-wink==0.6.0'] def setup_platform(hass, config, add_devices_callback, discovery_info=None): diff --git a/homeassistant/components/lock/wink.py b/homeassistant/components/lock/wink.py index 9c73c35d130b14892578ff82802d0f90a7a0bdf6..be558dceee7143cb3a2730024853110d7b282640 100644 --- a/homeassistant/components/lock/wink.py +++ b/homeassistant/components/lock/wink.py @@ -11,7 +11,7 @@ import logging from homeassistant.components.lock import LockDevice from homeassistant.const import CONF_ACCESS_TOKEN -REQUIREMENTS = ['python-wink==0.5.0'] +REQUIREMENTS = ['python-wink==0.6.0'] def setup_platform(hass, config, add_devices, discovery_info=None): diff --git a/homeassistant/components/sensor/wink.py b/homeassistant/components/sensor/wink.py index 48583426d72ec312dc8f3d6be0bd59cc228d427c..71fadff157bbc3ab02381ed49e691107a72169da 100644 --- a/homeassistant/components/sensor/wink.py +++ b/homeassistant/components/sensor/wink.py @@ -11,7 +11,7 @@ import logging from homeassistant.helpers.entity import Entity from homeassistant.const import CONF_ACCESS_TOKEN, STATE_OPEN, STATE_CLOSED -REQUIREMENTS = ['python-wink==0.5.0'] +REQUIREMENTS = ['python-wink==0.6.0'] def setup_platform(hass, config, add_devices, discovery_info=None): diff --git a/homeassistant/components/switch/wink.py b/homeassistant/components/switch/wink.py index 19abc1c4fce4ec50f0d5ea0ac3be14414a7b4838..23ba434ad2bfe6c39898a1bdccca7c487e50addb 100644 --- a/homeassistant/components/switch/wink.py +++ b/homeassistant/components/switch/wink.py @@ -11,7 +11,7 @@ import logging from homeassistant.components.wink import WinkToggleDevice from homeassistant.const import CONF_ACCESS_TOKEN -REQUIREMENTS = ['python-wink==0.5.0'] +REQUIREMENTS = ['python-wink==0.6.0'] def setup_platform(hass, config, add_devices, discovery_info=None): diff --git a/homeassistant/components/wink.py b/homeassistant/components/wink.py index 6fa2b9287e9c8921c49f20a7b82c7c192d030a0b..ef97e958dc0b79005b20689ef3b3efc0c49289fb 100644 --- a/homeassistant/components/wink.py +++ b/homeassistant/components/wink.py @@ -16,7 +16,7 @@ from homeassistant.const import ( ATTR_SERVICE, ATTR_DISCOVERED) DOMAIN = "wink" -REQUIREMENTS = ['python-wink==0.5.0'] +REQUIREMENTS = ['python-wink==0.6.0'] DISCOVER_LIGHTS = "wink.lights" DISCOVER_SWITCHES = "wink.switches" diff --git a/homeassistant/core.py b/homeassistant/core.py index 39a10beda8d5b946d91956201b4ea6c6f743dc0f..37f909e218a8ffd827b3b8f170d6d70046a12ec4 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -309,7 +309,7 @@ class State(object): "Format should be <domain>.<object_id>").format(entity_id)) self.entity_id = entity_id.lower() - self.state = state + self.state = str(state) self.attributes = MappingProxyType(attributes or {}) self.last_updated = dt_util.strip_microseconds( last_updated or dt_util.utcnow()) diff --git a/homeassistant/helpers/state.py b/homeassistant/helpers/state.py index 1a3520d47331658b4eeaa815a31ed6ad6a14e738..23673e678ca0dabc92ad5d592d6c5bccb35145c8 100644 --- a/homeassistant/helpers/state.py +++ b/homeassistant/helpers/state.py @@ -109,16 +109,5 @@ def state_as_number(state): elif state.state in (STATE_OFF, STATE_UNLOCKED, STATE_UNKNOWN, STATE_BELOW_HORIZON, STATE_CLOSED): return 0 - else: - try: - # This distinction is probably not important, - # but in case something downstream cares about - # int vs. float, try to be helpful here. - if '.' in state.state: - return float(state.state) - else: - return int(state.state) - except (ValueError, TypeError): - pass - - raise ValueError('State is not a number') + + return float(state.state) diff --git a/requirements_all.txt b/requirements_all.txt index b5532905ca36190eb5eecec237c8b8aa19b72d16..bfd1e8c7c45744c195277be1e1e97ff1366db3e8 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -199,7 +199,7 @@ python-twitch==1.2.0 # homeassistant.components.lock.wink # homeassistant.components.sensor.wink # homeassistant.components.switch.wink -python-wink==0.5.0 +python-wink==0.6.0 # homeassistant.components.keyboard pyuserinput==0.1.9 diff --git a/tests/components/test_graphite.py b/tests/components/test_graphite.py index c0ca228efe2a2e3ec89d2c15b9633726c384d176..34ad93a86c405ee3c78d827abb3e3cfa825332a3 100644 --- a/tests/components/test_graphite.py +++ b/tests/components/test_graphite.py @@ -89,6 +89,7 @@ class TestGraphite(unittest.TestCase): 'bat': 'NaN', } expected = [ + 'ha.entity.state 0.000000 12345', 'ha.entity.foo 1.000000 12345', 'ha.entity.bar 2.000000 12345', 'ha.entity.baz 1.000000 12345', diff --git a/tests/components/test_statsd.py b/tests/components/test_statsd.py index a793e519a2e22b47e009f1b1bd6d9059d1eebf81..5057ac7bc19f2eab2663b734f017dc84c7b798f6 100644 --- a/tests/components/test_statsd.py +++ b/tests/components/test_statsd.py @@ -7,6 +7,7 @@ Tests StatsD feeder. import unittest from unittest import mock +import homeassistant.core as ha import homeassistant.components.statsd as statsd from homeassistant.const import STATE_ON, STATE_OFF, EVENT_STATE_CHANGED @@ -78,6 +79,6 @@ class TestStatsd(unittest.TestCase): mock_gauge.return_value.send.reset_mock() for invalid in ('foo', '', object): - state = mock.MagicMock(state=invalid) - handler_method(mock.MagicMock(data={'new_state': state})) + handler_method(mock.MagicMock(data={ + 'new_state': ha.State('domain.test', invalid, {})})) self.assertFalse(mock_gauge.return_value.send.called) diff --git a/tests/helpers/test_state.py b/tests/helpers/test_state.py index 3924bd0489e84593929bcd8eec9641709fc80dfe..e11426e2f95c3b985d9adc56892be14d68dbd87a 100644 --- a/tests/helpers/test_state.py +++ b/tests/helpers/test_state.py @@ -163,24 +163,18 @@ class TestStateHelpers(unittest.TestCase): ha.State('domain.test', _state, {}))) def test_as_number_coercion(self): - for _state in ('0', '0.0'): - self.assertEqual(0.0, float( - state.state_as_number( - ha.State('domain.test', _state, {})))) - for _state in ('1', '1.0'): + for _state in ('0', '0.0', 0, 0.0): self.assertEqual( - 1.0, float(state.state_as_number( - ha.State('domain.test', _state, {})))) - - def test_as_number_tries_to_keep_types(self): - result = state.state_as_number(ha.State('domain.test', '1', {})) - self.assertTrue(isinstance(result, int)) - result = state.state_as_number(ha.State('domain.test', '1.0', {})) - self.assertTrue(isinstance(result, float)) + 0.0, state.state_as_number( + ha.State('domain.test', _state, {}))) + for _state in ('1', '1.0', 1, 1.0): + self.assertEqual( + 1.0, state.state_as_number( + ha.State('domain.test', _state, {}))) def test_as_number_invalid_cases(self): - for _state in ('', 'foo', 'foo.bar', None, False, True, None, - object, object()): + for _state in ('', 'foo', 'foo.bar', None, False, True, object, + object()): self.assertRaises(ValueError, state.state_as_number, ha.State('domain.test', _state, {}))