def test_invalid_data(self, req_mock): """Test the WUnderground invalid data.""" wunderground.setup_platform(self.hass, VALID_CONFIG_PWS, self.add_devices, None) for device in self.DEVICES: device.update() self.assertEqual(STATE_UNKNOWN, device.state)
def test_sensor(self, req_mock): """Test the WUnderground sensor class and methods.""" wunderground.setup_platform(self.hass, VALID_CONFIG, self.add_devices, None) for device in self.DEVICES: device.update() self.assertTrue(str(device.name).startswith('PWS_')) if device.name == 'PWS_weather': self.assertEqual(HTTPS_ICON_URL, device.entity_picture) self.assertEqual(WEATHER, device.state) self.assertIsNone(device.unit_of_measurement) elif device.name == 'PWS_alerts': self.assertEqual(1, device.state) self.assertEqual(ALERT_MESSAGE, device.device_state_attributes['Message']) self.assertIsNone(device.entity_picture) elif device.name == 'PWS_location': self.assertEqual('Holly Springs, NC', device.state) elif device.name == 'PWS_elevation': self.assertEqual('413', device.state) elif device.name == 'PWS_feelslike_c': self.assertIsNone(device.entity_picture) self.assertEqual(FEELS_LIKE, device.state) self.assertEqual(TEMP_CELSIUS, device.unit_of_measurement) elif device.name == 'PWS_weather_1d_metric': self.assertEqual(FORECAST_TEXT, device.state) else: self.assertEqual(device.name, 'PWS_precip_1d_in') self.assertEqual(PRECIP_IN, device.state) self.assertEqual(LENGTH_INCHES, device.unit_of_measurement)
def test_setup(self, req_mock): """Test that the component is loaded if passed in PWS Id.""" self.assertTrue(wunderground.setup_platform(self.hass, VALID_CONFIG_PWS, self.add_devices, None)) self.assertTrue(wunderground.setup_platform(self.hass, VALID_CONFIG, self.add_devices, None)) invalid_config = { "platform": "wunderground", "api_key": "BOB", "pws_id": "bar", "monitored_conditions": ["weather", "feelslike_c"], } self.assertFalse(wunderground.setup_platform(self.hass, invalid_config, self.add_devices, None))
def test_setup(self, req_mock): """Test that the component is loaded if passed in PWS Id.""" self.assertTrue( wunderground.setup_platform(self.hass, VALID_CONFIG_PWS, self.add_devices, None)) self.assertTrue( wunderground.setup_platform(self.hass, VALID_CONFIG, self.add_devices, None)) self.assertTrue( wunderground.setup_platform(self.hass, INVALID_CONFIG, self.add_devices, None))
def test_sensor(self, req_mock): """Test the WUnderground sensor class and methods.""" wunderground.setup_platform(self.hass, VALID_CONFIG, self.add_devices, None) for device in self.DEVICES: self.assertTrue(str(device.name).startswith("PWS_")) if device.name == "PWS_weather": self.assertEqual(ICON_URL, device.entity_picture) self.assertEqual(WEATHER, device.state) self.assertIsNone(device.unit_of_measurement) else: self.assertIsNone(device.entity_picture) self.assertEqual(FEELS_LIKE, device.state) self.assertEqual(TEMP_CELSIUS, device.unit_of_measurement)
def test_setup(self, req_mock): """Test that the component is loaded if passed in PWS Id.""" self.assertTrue( wunderground.setup_platform(self.hass, VALID_CONFIG_PWS, self.add_devices, None)) self.assertTrue( wunderground.setup_platform(self.hass, VALID_CONFIG, self.add_devices, None)) invalid_config = { 'platform': 'wunderground', 'api_key': 'BOB', 'pws_id': 'bar', 'monitored_conditions': [ 'weather', 'feelslike_c', 'alerts' ] } self.assertTrue( wunderground.setup_platform(self.hass, invalid_config, self.add_devices, None))
def test_sensor(self, req_mock): """Test the WUnderground sensor class and methods.""" wunderground.setup_platform(self.hass, VALID_CONFIG, self.add_devices, None) for device in self.DEVICES: device.update() self.assertTrue(str(device.name).startswith('PWS_')) if device.name == 'PWS_weather': self.assertEqual(HTTPS_ICON_URL, device.entity_picture) self.assertEqual(WEATHER, device.state) self.assertIsNone(device.unit_of_measurement) elif device.name == 'PWS_alerts': self.assertEqual(1, device.state) self.assertEqual(ALERT_MESSAGE, device.device_state_attributes['Message']) self.assertIsNone(device.entity_picture) elif device.name == 'PWS_location': self.assertEqual('Holly Springs, NC', device.state) elif device.name == 'PWS_elevation': self.assertEqual('413', device.state) else: self.assertIsNone(device.entity_picture) self.assertEqual(FEELS_LIKE, device.state) self.assertEqual(TEMP_CELSIUS, device.unit_of_measurement)
def test_connect_failed(self, req_mock): """Test the WUnderground connection error.""" with self.assertRaises(PlatformNotReady): wunderground.setup_platform(self.hass, VALID_CONFIG, self.add_devices, None)