def test_object_wrong_property(dbus_service): """ Try to get an inexistent property and verify that an error is returned. """ interface = 'com.example.interface1' addr = DBusAddress('/path', dbus_service.name, interface=interface) dbus_service.listen() conn = connect_and_authenticate() with pytest.raises(DBusErrorResponse): conn.send_and_get_reply(Properties(addr).get('prop'))
def test_object_get_property(dbus_service): """ Set and get properties from a dbus object. """ interface = 'com.example.interface1' add0 = DBusAddress('/path', dbus_service.name, interface=interface) add1 = DBusAddress('/path/subpath', dbus_service.name, interface=interface) dbus_service.set_property(add0.object_path, 'prop0', 's', ('hello0',), add0.interface) dbus_service.set_property(add1.object_path, 'prop1', 's', ('hello1',), add1.interface) dbus_service.listen() conn = connect_and_authenticate() response = conn.send_and_get_reply(Properties(add0).get('prop0')) assert response == ('hello0', ) response = conn.send_and_get_reply(Properties(add1).get('prop1')) assert response == ('hello1', )
async def addTrack(self, track): trackIdTail = "/org/mpris/MediaPlayer2/TrackList/Append" # Resume playing if necessary properties = Proxy(Properties(Player()), self.router) status = await properties.get("PlaybackStatus") resume = status[0] == ("s", "Stopped") self.tracks.append(track) tracklist = Proxy(TrackList(), self.router) message = tracklist.AddTrack(track.url, trackIdTail, resume) await self.notifyListChange(message) return self.tracks
async def notifyListChange(self, message=None): # Regenerate etag self.uuid = uuid4() # Send request to change the tracklist if message: await message # Read tracklist again to match player's track id with our tracklist properties = Proxy(Properties(TrackList()), self.router) tracks = await properties.get("Tracks") print("Tracklist has changed: {}".format(repr(tracks))) # Notify subscribers with new tracklist state = QueueState(self) await asyncio.gather(*[client.put(state) for client in self.listeners])
def test_object_get_all_properties(dbus_service): """ Get all properties from a dbus object. """ interface = 'com.example.interface1' addr = DBusAddress('/path', dbus_service.name, interface=interface) dbus_service.set_property(addr.object_path, 'prop0', 's', 'hello0', addr.interface) dbus_service.set_property(addr.object_path, 'prop1', 's', 'hello1', addr.interface) dbus_service.set_property(addr.object_path, 'prop2', 's', 'hello2', addr.interface) dbus_service.listen() conn = connect_and_authenticate() response = conn.send_and_get_reply(Properties(addr).get_all()) assert response == ([('prop0', ('s', 'hello0')), ('prop1', ('s', 'hello1')), ('prop2', ('s', 'hello2'))], )
def test_object_set_readonly_property(dbus_service): """ Try to set the value for a readonly property and check that a permissions error is returned. """ name = 'someprop' value = ('somevalue',) path = '/' interface = 'some.interface' prop = DBusProperty(name, 's', value, access='read') dbus_service.interfaces[(path, interface)].properties[name] = prop dbus_service.listen() conn = connect_and_authenticate() addr = DBusAddress(path, dbus_service.name, interface) msg = Properties(addr).set(name, 's', 'anothervalue') with pytest.raises(DBusErrorResponse) as err: conn.send_and_get_reply(msg) assert err.value.name == 'com.example.object.exceptions.PermissionError' assert err.value.data == (f'{name}: Property not settable',) # check that the original property hasn't changed assert prop.value == value
def set_property(self, name: str, signature: str, value: Any) -> None: msg = Properties(self).set(name, signature, value) self.send_and_get_reply(msg)
def get_property(self, name: str) -> Any: msg = Properties(self).get(name) (signature, value), = self.send_and_get_reply(msg) return value