예제 #1
0
    def test_update_sensor_with_category(self):
        """Test updating sensor object."""
        raw_data = load_fixture('geo_rss_events.xml')
        # Loading raw data from fixture and plug in to data object as URL
        # works since the third-party feedparser library accepts a URL
        # as well as the actual data.
        data = self.setup_data(raw_data)
        category = "Category 1"
        name = "Name 1"
        unit_of_measurement = "Unit 1"
        sensor = geo_rss_events.GeoRssServiceSensor(category, data, name,
                                                    unit_of_measurement)

        sensor.update()
        assert sensor.name == "Name 1 Category 1"
        assert sensor.unit_of_measurement == "Unit 1"
        assert sensor.icon == "mdi:alert"
        assert len(sensor._data.events) == 4
        assert sensor.state == 1
        assert sensor.device_state_attributes == {'Title 1': "117km"}
        # Check entries of first hit
        assert sensor._data.events[0][geo_rss_events.ATTR_TITLE] == "Title 1"
        assert sensor._data.events[0][
            geo_rss_events.ATTR_CATEGORY] == "Category 1"
        self.assertAlmostEqual(
            sensor._data.events[0][geo_rss_events.ATTR_DISTANCE], 116.586, 0)
예제 #2
0
    def test_update_sensor_with_none_result(self, parse_function):
        """Test updating sensor object."""
        data = self.setup_data("http://invalid.url/")
        category = None
        name = "Name 4"
        unit_of_measurement = "Unit 4"
        sensor = geo_rss_events.GeoRssServiceSensor(category, data, name,
                                                    unit_of_measurement)

        sensor.update()
        assert sensor.name == "Name 4 Any"
        assert sensor.unit_of_measurement == "Unit 4"
        assert sensor.state == 0
예제 #3
0
    def test_update_sensor_without_data(self):
        """Test updating sensor object."""
        data = self.setup_data()
        category = None
        name = "Name 3"
        unit_of_measurement = "Unit 3"
        sensor = geo_rss_events.GeoRssServiceSensor(category, data, name,
                                                    unit_of_measurement)

        sensor.update()
        assert sensor.name == "Name 3 Any"
        assert sensor.unit_of_measurement == "Unit 3"
        assert sensor.icon == "mdi:alert"
        assert len(sensor._data.events) == 0
        assert sensor.state == 0
예제 #4
0
    def test_update_sensor_without_category(self):
        """Test updating sensor object."""
        raw_data = load_fixture('geo_rss_events.xml')
        data = self.setup_data(raw_data)
        category = None
        name = "Name 2"
        unit_of_measurement = "Unit 2"
        sensor = geo_rss_events.GeoRssServiceSensor(category, data, name,
                                                    unit_of_measurement)

        sensor.update()
        assert sensor.name == "Name 2 Any"
        assert sensor.unit_of_measurement == "Unit 2"
        assert sensor.icon == "mdi:alert"
        assert len(sensor._data.events) == 4
        assert sensor.state == 4
        assert sensor.device_state_attributes == {
            'Title 1': "117km",
            'Title 2': "302km",
            'Title 3': "204km",
            'Title 6': "48km"
        }