示例#1
0
    def test_temperature_sensor_with_none_sensor_value(self):
        """Test temperature sensor with fahrenheit."""
        device = mock_device(10, "Family Room", "Canary")
        location = mock_location("Home", False)

        data = Mock()
        data.get_reading.return_value = None

        sensor = CanarySensor(data, SENSOR_TYPES[0], location, device)
        sensor.update()

        assert sensor.state is None
示例#2
0
    def test_air_quality_sensor_with_none_sensor_value(self):
        """Test air quality sensor."""
        device = mock_device(10, "Family Room", "Canary")
        location = mock_location("Home")

        data = Mock()
        data.get_reading.return_value = None

        sensor = CanarySensor(data, SENSOR_TYPES[2], location, device)
        sensor.update()

        assert sensor.state is None
        assert sensor.device_state_attributes is None
    def test_humidity_sensor(self):
        """Test humidity sensor."""
        device = mock_device(10, "Family Room")
        location = mock_location("Home")

        data = Mock()
        data.get_reading.return_value = 50.4567

        sensor = CanarySensor(data, SENSOR_TYPES[1], location, device)
        sensor.update()

        self.assertEqual("Home Family Room Humidity", sensor.name)
        self.assertEqual("%", sensor.unit_of_measurement)
        self.assertEqual(50.46, sensor.state)
    def test_temperature_sensor(self):
        """Test temperature sensor with fahrenheit."""
        device = mock_device(10, "Family Room")
        location = mock_location("Home", False)

        data = Mock()
        data.get_reading.return_value = 21.1234

        sensor = CanarySensor(data, SENSOR_TYPES[0], location, device)
        sensor.update()

        self.assertEqual("Home Family Room Temperature", sensor.name)
        self.assertEqual("°C", sensor.unit_of_measurement)
        self.assertEqual(21.12, sensor.state)
示例#5
0
    def test_humidity_sensor(self):
        """Test humidity sensor."""
        device = mock_device(10, "Family Room")
        location = mock_location("Home")

        data = Mock()
        data.get_readings.return_value = [
            mock_reading(SensorType.HUMIDITY, 50.4567)]

        sensor = CanarySensor(data, SensorType.HUMIDITY, location, device)
        sensor.update()

        self.assertEqual("Home Family Room Humidity", sensor.name)
        self.assertEqual("%", sensor.unit_of_measurement)
        self.assertEqual(50.5, sensor.state)
示例#6
0
    def test_fahrenheit_temperature_sensor(self):
        """Test temperature sensor with fahrenheit."""
        device = mock_device(10, "Family Room")
        location = mock_location("Home", False)

        data = Mock()
        data.get_readings.return_value = [
            mock_reading(SensorType.TEMPERATURE, 21.1567)]

        sensor = CanarySensor(data, SensorType.TEMPERATURE, location, device)
        sensor.update()

        self.assertEqual("Home Family Room Temperature", sensor.name)
        self.assertEqual("°F", sensor.unit_of_measurement)
        self.assertEqual(21.2, sensor.state)
示例#7
0
    def test_humidity_sensor(self):
        """Test humidity sensor."""
        device = mock_device(10, "Family Room", "Canary")
        location = mock_location("Home")

        data = Mock()
        data.get_reading.return_value = 50.4567

        sensor = CanarySensor(data, SENSOR_TYPES[1], location, device)
        sensor.update()

        assert "Home Family Room Humidity" == sensor.name
        assert "%" == sensor.unit_of_measurement
        assert 50.46 == sensor.state
        assert "mdi:water-percent" == sensor.icon
示例#8
0
    def test_temperature_sensor(self):
        """Test temperature sensor with fahrenheit."""
        device = mock_device(10, "Family Room", "Canary")
        location = mock_location("Home", False)

        data = Mock()
        data.get_reading.return_value = 21.1234

        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
示例#9
0
    def test_wifi_sensor(self):
        """Test battery sensor."""
        device = mock_device(10, "Family Room", "Canary Flex")
        location = mock_location("Home")

        data = Mock()
        data.get_reading.return_value = -57

        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
示例#10
0
    def test_battery_sensor(self):
        """Test battery sensor."""
        device = mock_device(10, "Family Room", "Canary Flex")
        location = mock_location("Home")

        data = Mock()
        data.get_reading.return_value = 70.4567

        sensor = CanarySensor(data, SENSOR_TYPES[4], location, device)
        sensor.update()

        assert "Home Family Room Battery" == sensor.name
        assert "%" == sensor.unit_of_measurement
        assert 70.46 == sensor.state
        assert "mdi:battery-70" == sensor.icon
示例#11
0
    def test_celsius_temperature_sensor(self):
        """Test temperature sensor with celsius."""
        device = mock_device(10, "Family Room")
        location = mock_location("Home", True)

        data = Mock()
        data.get_readings.return_value = [
            mock_reading(SensorType.TEMPERATURE, 21.1234)]

        sensor = CanarySensor(data, SensorType.TEMPERATURE, location, device)
        sensor.update()

        self.assertEqual("Home Family Room Temperature", sensor.name)
        self.assertEqual("sensor_canary_10_temperature", sensor.unique_id)
        self.assertEqual("°C", sensor.unit_of_measurement)
        self.assertEqual(21.1, sensor.state)
示例#12
0
    def test_humidity_sensor(self):
        """Test humidity sensor."""
        device = mock_device(10, "Family Room")
        location = mock_location("Home")

        data = Mock()
        data.get_readings.return_value = [
            mock_reading(SensorType.HUMIDITY, 50.4567)
        ]

        sensor = CanarySensor(data, SensorType.HUMIDITY, location, device)
        sensor.update()

        self.assertEqual("Home Family Room Humidity", sensor.name)
        self.assertEqual("%", sensor.unit_of_measurement)
        self.assertEqual(50.5, sensor.state)
示例#13
0
    def test_fahrenheit_temperature_sensor(self):
        """Test temperature sensor with fahrenheit."""
        device = mock_device(10, "Family Room")
        location = mock_location("Home", False)

        data = Mock()
        data.get_readings.return_value = [
            mock_reading(SensorType.TEMPERATURE, 21.1567)
        ]

        sensor = CanarySensor(data, SensorType.TEMPERATURE, location, device)
        sensor.update()

        self.assertEqual("Home Family Room Temperature", sensor.name)
        self.assertEqual("°F", sensor.unit_of_measurement)
        self.assertEqual(21.2, sensor.state)
    def test_air_quality_sensor_with_normal_reading(self):
        """Test air quality sensor."""
        device = mock_device(10, "Family Room")
        location = mock_location("Home")

        data = Mock()
        data.get_reading.return_value = 1.0

        sensor = CanarySensor(data, SENSOR_TYPES[2], location, device)
        sensor.update()

        self.assertEqual("Home Family Room Air Quality", sensor.name)
        self.assertEqual(None, sensor.unit_of_measurement)
        self.assertEqual(1.0, sensor.state)

        air_quality = sensor.device_state_attributes[ATTR_AIR_QUALITY]
        self.assertEqual(STATE_AIR_QUALITY_NORMAL, air_quality)
示例#15
0
    def test_celsius_temperature_sensor(self):
        """Test temperature sensor with celsius."""
        device = mock_device(10, "Family Room")
        location = mock_location("Home", True)

        data = Mock()
        data.get_readings.return_value = [
            mock_reading(SensorType.TEMPERATURE, 21.1234)
        ]

        sensor = CanarySensor(data, SensorType.TEMPERATURE, location, device)
        sensor.update()

        self.assertEqual("Home Family Room Temperature", sensor.name)
        self.assertEqual("sensor_canary_10_temperature", sensor.unique_id)
        self.assertEqual("°C", sensor.unit_of_measurement)
        self.assertEqual(21.1, sensor.state)
示例#16
0
    def test_air_quality_sensor_with_normal_reading(self):
        """Test air quality sensor."""
        device = mock_device(10, "Family Room", "Canary")
        location = mock_location("Home")

        data = Mock()
        data.get_reading.return_value = 1.0

        sensor = CanarySensor(data, SENSOR_TYPES[2], location, device)
        sensor.update()

        assert "Home Family Room Air Quality" == sensor.name
        assert sensor.unit_of_measurement is None
        assert 1.0 == sensor.state
        assert "mdi:weather-windy" == sensor.icon

        air_quality = sensor.device_state_attributes[ATTR_AIR_QUALITY]
        assert STATE_AIR_QUALITY_NORMAL == air_quality