def setup_platform(hass, config, add_devices, discovery_info=None): """Setup Openhome Platform.""" from openhomedevice.Device import Device if discovery_info: _LOGGER.info('Openhome device found, (%s)', discovery_info[0]) device = Device(discovery_info[1]) # if device has already been discovered if device.Uuid() in [x.unique_id for x in DEVICES]: return True device = OpenhomeDevice(hass, device) add_devices([device], True) DEVICES.append(device) return True return True
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Openhome platform.""" if not discovery_info: return True name = discovery_info.get("name") description = discovery_info.get("ssdp_description") _LOGGER.info("Openhome device found: %s", name) device = Device(description) # if device has already been discovered if device.Uuid() in [x.unique_id for x in DEVICES]: return True device = OpenhomeDevice(hass, device) add_entities([device], True) DEVICES.append(device) return True
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup Openhome Platform.""" from openhomedevice.Device import Device if not discovery_info: return True name = discovery_info.get('name') description = discovery_info.get('ssdp_description') _LOGGER.info('Openhome device found, (%s)', name) device = Device(description) # if device has already been discovered if device.Uuid() in [x.unique_id for x in DEVICES]: return True device = OpenhomeDevice(hass, device) add_devices([device], True) DEVICES.append(device) return True
class DidlLiteTests(unittest.TestCase): LOCATION = "http://*****:*****@patch("requests.get", side_effect=mocked_requests_get) @patch("openhomedevice.Soap.soapRequest", side_effect=mocked_soap_request) def setUp(self, patched_soap_request, patched_get): from openhomedevice.Device import Device global soap_request_calls self.sut = Device(self.LOCATION) soap_request_calls = [] return super().setUp() def test_device_parses_uuid(self): self.assertEqual(self.sut.Uuid(), "509a3dc9-d32b-30a1-ffff-ffff8842af55") def test_device_advertises_transport_service(self): self.assertFalse(self.sut.HasTransportService()) def test_device_name(self): self.assertEqual(self.sut.Name(), b"My Friendly Name") def test_room_name(self): self.assertEqual(self.sut.Room(), b"Bathroom") def test_set_standby_off(self): self.sut.SetStandby(False) self.assertEqual(soap_request_calls[0][3], "<Value>0</Value>") def test_set_standby_on(self): self.sut.SetStandby(True) self.assertEqual(soap_request_calls[0][3], "<Value>1</Value>") def test_is_in_standby(self): self.assertEqual(self.sut.IsInStandby(), True) def test_play_media_with_nothing(self): self.sut.PlayMedia(None) self.assertEqual(len(soap_request_calls), 0) def test_play_media_with_details(self): from openhomedevice.DidlLite import didlLiteString track_details = {} track_details["uri"] = "https://host/uri.flac" track_details["title"] = "TITLE" track_details["albumArtwork"] = "https://host/uri.jpg" expectedValue = "<Uri>{0}</Uri><Metadata>{1}</Metadata>".format( "https://host/uri.flac", didlLiteString(track_details) ) self.sut.PlayMedia(track_details) self.assertEqual(soap_request_calls[0][3], expectedValue) def test_play_media_with_invalid_uri(self): from openhomedevice.DidlLite import didlLiteString track_details = {} track_details["title"] = "TITLE" track_details["albumArtwork"] = "https://host/uri.jpg" expectedValue = "<Uri></Uri><Metadata>{0}</Metadata>".format( didlLiteString(track_details) ) self.sut.PlayMedia(track_details) self.assertEqual(soap_request_calls[0][3], expectedValue) def test_number_of_pins(self): self.assertListEqual( self.sut.Pins(), [], ) def test_invoke_pin(self): self.sut.InvokePin(42) self.assertEqual(len(soap_request_calls), 0)