diff --git a/homeassistant/components/canary/alarm_control_panel.py b/homeassistant/components/canary/alarm_control_panel.py index cceb78743d3..35fff8accbd 100644 --- a/homeassistant/components/canary/alarm_control_panel.py +++ b/homeassistant/components/canary/alarm_control_panel.py @@ -49,7 +49,6 @@ class CanaryAlarm(AlarmControlPanel): @property def state(self): """Return the state of the device.""" - location = self._data.get_location(self._location_id) if location.is_private: @@ -82,15 +81,16 @@ class CanaryAlarm(AlarmControlPanel): def alarm_arm_home(self, code=None): """Send arm home command.""" - self._data.set_location_mode(self._location_id, LOCATION_MODE_HOME) def alarm_arm_away(self, code=None): """Send arm away command.""" - self._data.set_location_mode(self._location_id, LOCATION_MODE_AWAY) def alarm_arm_night(self, code=None): """Send arm night command.""" - self._data.set_location_mode(self._location_id, LOCATION_MODE_NIGHT) + + def update(self): + """Get the latest state of the sensor.""" + self._data.update() diff --git a/homeassistant/components/canary/sensor.py b/homeassistant/components/canary/sensor.py index 09413f9cb61..88b42d296ed 100644 --- a/homeassistant/components/canary/sensor.py +++ b/homeassistant/components/canary/sensor.py @@ -10,14 +10,21 @@ from . import DATA_CANARY SENSOR_VALUE_PRECISION = 2 ATTR_AIR_QUALITY = "air_quality" +# Define variables to store the device names, as referred to by the Canary API. +# Note: If Canary change the name of any of their devices (which they have done), +# then these variables will need updating, otherwise the sensors will stop working +# and disappear in Home Assistant. +CANARY_PRO = "Canary Pro" +CANARY_FLEX = "Canary Flex" + # Sensor types are defined like so: # sensor type name, unit_of_measurement, icon SENSOR_TYPES = [ - ["temperature", TEMP_CELSIUS, "mdi:thermometer", ["Canary"]], - ["humidity", UNIT_PERCENTAGE, "mdi:water-percent", ["Canary"]], - ["air_quality", None, "mdi:weather-windy", ["Canary"]], - ["wifi", "dBm", "mdi:wifi", ["Canary Flex"]], - ["battery", UNIT_PERCENTAGE, "mdi:battery-50", ["Canary Flex"]], + ["temperature", TEMP_CELSIUS, "mdi:thermometer", [CANARY_PRO]], + ["humidity", UNIT_PERCENTAGE, "mdi:water-percent", [CANARY_PRO]], + ["air_quality", None, "mdi:weather-windy", [CANARY_PRO]], + ["wifi", "dBm", "mdi:wifi", [CANARY_FLEX]], + ["battery", UNIT_PERCENTAGE, "mdi:battery-50", [CANARY_FLEX]], ] STATE_AIR_QUALITY_NORMAL = "normal" diff --git a/tests/components/canary/test_sensor.py b/tests/components/canary/test_sensor.py index b9d8be50b90..6cc33ddf610 100644 --- a/tests/components/canary/test_sensor.py +++ b/tests/components/canary/test_sensor.py @@ -41,9 +41,9 @@ class TestCanarySensorSetup(unittest.TestCase): def test_setup_sensors(self): """Test the sensor setup.""" - online_device_at_home = mock_device(20, "Dining Room", True, "Canary") - offline_device_at_home = mock_device(21, "Front Yard", False, "Canary") - online_device_at_work = mock_device(22, "Office", True, "Canary") + online_device_at_home = mock_device(20, "Dining Room", True, "Canary Pro") + offline_device_at_home = mock_device(21, "Front Yard", False, "Canary Pro") + online_device_at_work = mock_device(22, "Office", True, "Canary Pro") self.hass.data[DATA_CANARY] = Mock() self.hass.data[DATA_CANARY].locations = [ @@ -55,11 +55,11 @@ class TestCanarySensorSetup(unittest.TestCase): canary.setup_platform(self.hass, self.config, self.add_entities, None) - assert 6 == len(self.DEVICES) + assert len(self.DEVICES) == 6 def test_temperature_sensor(self): """Test temperature sensor with fahrenheit.""" - device = mock_device(10, "Family Room", "Canary") + device = mock_device(10, "Family Room", "Canary Pro") location = mock_location("Home", False) data = Mock() @@ -68,14 +68,14 @@ class TestCanarySensorSetup(unittest.TestCase): sensor = CanarySensor(data, SENSOR_TYPES[0], location, device) sensor.update() - assert "Home Family Room Temperature" == sensor.name - assert "°C" == sensor.unit_of_measurement - assert 21.12 == sensor.state - assert "mdi:thermometer" == sensor.icon + assert sensor.name == "Home Family Room Temperature" + assert sensor.unit_of_measurement == "°C" + assert sensor.state == 21.12 + assert sensor.icon == "mdi:thermometer" def test_temperature_sensor_with_none_sensor_value(self): """Test temperature sensor with fahrenheit.""" - device = mock_device(10, "Family Room", "Canary") + device = mock_device(10, "Family Room", "Canary Pro") location = mock_location("Home", False) data = Mock() @@ -88,7 +88,7 @@ class TestCanarySensorSetup(unittest.TestCase): def test_humidity_sensor(self): """Test humidity sensor.""" - device = mock_device(10, "Family Room", "Canary") + device = mock_device(10, "Family Room", "Canary Pro") location = mock_location("Home") data = Mock() @@ -97,14 +97,14 @@ class TestCanarySensorSetup(unittest.TestCase): sensor = CanarySensor(data, SENSOR_TYPES[1], location, device) sensor.update() - assert "Home Family Room Humidity" == sensor.name - assert UNIT_PERCENTAGE == sensor.unit_of_measurement - assert 50.46 == sensor.state - assert "mdi:water-percent" == sensor.icon + assert sensor.name == "Home Family Room Humidity" + assert sensor.unit_of_measurement == UNIT_PERCENTAGE + assert sensor.state == 50.46 + assert sensor.icon == "mdi:water-percent" def test_air_quality_sensor_with_very_abnormal_reading(self): """Test air quality sensor.""" - device = mock_device(10, "Family Room", "Canary") + device = mock_device(10, "Family Room", "Canary Pro") location = mock_location("Home") data = Mock() @@ -113,17 +113,17 @@ class TestCanarySensorSetup(unittest.TestCase): sensor = CanarySensor(data, SENSOR_TYPES[2], location, device) sensor.update() - assert "Home Family Room Air Quality" == sensor.name + assert sensor.name == "Home Family Room Air Quality" assert sensor.unit_of_measurement is None - assert 0.4 == sensor.state - assert "mdi:weather-windy" == sensor.icon + assert sensor.state == 0.4 + assert sensor.icon == "mdi:weather-windy" air_quality = sensor.device_state_attributes[ATTR_AIR_QUALITY] - assert STATE_AIR_QUALITY_VERY_ABNORMAL == air_quality + assert air_quality == STATE_AIR_QUALITY_VERY_ABNORMAL def test_air_quality_sensor_with_abnormal_reading(self): """Test air quality sensor.""" - device = mock_device(10, "Family Room", "Canary") + device = mock_device(10, "Family Room", "Canary Pro") location = mock_location("Home") data = Mock() @@ -132,17 +132,17 @@ class TestCanarySensorSetup(unittest.TestCase): sensor = CanarySensor(data, SENSOR_TYPES[2], location, device) sensor.update() - assert "Home Family Room Air Quality" == sensor.name + assert sensor.name == "Home Family Room Air Quality" assert sensor.unit_of_measurement is None - assert 0.59 == sensor.state - assert "mdi:weather-windy" == sensor.icon + assert sensor.state == 0.59 + assert sensor.icon == "mdi:weather-windy" air_quality = sensor.device_state_attributes[ATTR_AIR_QUALITY] - assert STATE_AIR_QUALITY_ABNORMAL == air_quality + assert air_quality == STATE_AIR_QUALITY_ABNORMAL def test_air_quality_sensor_with_normal_reading(self): """Test air quality sensor.""" - device = mock_device(10, "Family Room", "Canary") + device = mock_device(10, "Family Room", "Canary Pro") location = mock_location("Home") data = Mock() @@ -151,17 +151,17 @@ class TestCanarySensorSetup(unittest.TestCase): sensor = CanarySensor(data, SENSOR_TYPES[2], location, device) sensor.update() - assert "Home Family Room Air Quality" == sensor.name + assert sensor.name == "Home Family Room Air Quality" assert sensor.unit_of_measurement is None - assert 1.0 == sensor.state - assert "mdi:weather-windy" == sensor.icon + assert sensor.state == 1.0 + assert sensor.icon == "mdi:weather-windy" air_quality = sensor.device_state_attributes[ATTR_AIR_QUALITY] - assert STATE_AIR_QUALITY_NORMAL == air_quality + assert air_quality == STATE_AIR_QUALITY_NORMAL def test_air_quality_sensor_with_none_sensor_value(self): """Test air quality sensor.""" - device = mock_device(10, "Family Room", "Canary") + device = mock_device(10, "Family Room", "Canary Pro") location = mock_location("Home") data = Mock() @@ -184,10 +184,10 @@ class TestCanarySensorSetup(unittest.TestCase): sensor = CanarySensor(data, SENSOR_TYPES[4], location, device) sensor.update() - assert "Home Family Room Battery" == sensor.name - assert UNIT_PERCENTAGE == sensor.unit_of_measurement - assert 70.46 == sensor.state - assert "mdi:battery-70" == sensor.icon + assert sensor.name == "Home Family Room Battery" + assert sensor.unit_of_measurement == UNIT_PERCENTAGE + assert sensor.state == 70.46 + assert sensor.icon == "mdi:battery-70" def test_wifi_sensor(self): """Test battery sensor.""" @@ -200,7 +200,7 @@ class TestCanarySensorSetup(unittest.TestCase): sensor = CanarySensor(data, SENSOR_TYPES[3], location, device) sensor.update() - assert "Home Family Room Wifi" == sensor.name - assert "dBm" == sensor.unit_of_measurement - assert -57 == sensor.state - assert "mdi:wifi" == sensor.icon + assert sensor.name == "Home Family Room Wifi" + assert sensor.unit_of_measurement == "dBm" + assert sensor.state == -57 + assert sensor.icon == "mdi:wifi"