diff --git a/denonavr/api.py b/denonavr/api.py index ed53b5a..5da73b9 100644 --- a/denonavr/api.py +++ b/denonavr/api.py @@ -131,9 +131,7 @@ async def async_get( # Use default port of the receiver if no different port is specified port = port if port is not None else self.port - endpoint = "http://{host}:{port}{request}".format( - host=self.host, port=port, request=request - ) + endpoint = f"http://{self.host}:{port}{request}" client = self.async_client_getter() try: @@ -158,9 +156,7 @@ async def async_post( # Use default port of the receiver if no different port is specified port = port if port is not None else self.port - endpoint = "http://{host}:{port}{request}".format( - host=self.host, port=port, request=request - ) + endpoint = f"http://{self.host}:{port}{request}" client = self.async_client_getter() try: @@ -225,7 +221,7 @@ async def async_post_appcommand( def add_appcommand_update_tag(self, tag: AppCommandCmd) -> None: """Add appcommand tag for full update.""" if tag.cmd_id != "1": - raise ValueError("cmd_id is {} but must be 1".format(tag.cmd_id)) + raise ValueError(f"cmd_id is {tag.cmd_id} but must be 1") # Remove response pattern from tag because it is not relevant for query tag = attr.evolve(tag, response_pattern=tuple()) @@ -237,7 +233,7 @@ def add_appcommand_update_tag(self, tag: AppCommandCmd) -> None: def add_appcommand0300_update_tag(self, tag: AppCommandCmd) -> None: """Add appcommand0300 tag for full update.""" if tag.cmd_id != "3": - raise ValueError("cmd_id is {} but must be 3".format(tag.cmd_id)) + raise ValueError(f"cmd_id is {tag.cmd_id} but must be 3") # Remove response pattern from tag because it is not relevant for query tag = attr.evolve(tag, response_pattern=tuple()) @@ -271,16 +267,20 @@ def add_query_tags_to_result( """ if len(cmd_list) != len(xml_root): raise AvrIncompleteResponseError( - "Invalid length of response XML. Query has {} elements, " - "response {}".format(len(cmd_list), len(xml_root)), + ( + "Invalid length of response XML. Query has" + f" {len(cmd_list)} elements, response {len(xml_root)}" + ), request, ) for i, child in enumerate(xml_root): if child.tag not in ["cmd", "error"]: raise AvrInvalidResponseError( - 'Returned document contains a tag other than "cmd" and ' - '"error": {}'.format(child.tag), + ( + 'Returned document contains a tag other than "cmd" and' + f' "error": {child.tag}' + ), request, ) # Find corresponding attributes from request XML if set and add @@ -460,21 +460,19 @@ async def _async_establish_connection(self) -> None: ) except asyncio.TimeoutError as err: _LOGGER.debug("%s: Timeout exception on telnet connect", self.host) - raise AvrTimoutError( - "TimeoutException: {}".format(err), "telnet connect" - ) from err + raise AvrTimoutError(f"TimeoutException: {err}", "telnet connect") from err except ConnectionRefusedError as err: _LOGGER.debug( "%s: Connection refused on telnet connect", self.host, exc_info=True ) raise AvrNetworkError( - "ConnectionRefusedError: {}".format(err), "telnet connect" + f"ConnectionRefusedError: {err}", "telnet connect" ) from err except (OSError, IOError) as err: _LOGGER.debug( "%s: Connection failed on telnet reconnect", self.host, exc_info=True ) - raise AvrNetworkError("OSError: {}".format(err), "telnet connect") from err + raise AvrNetworkError(f"OSError: {err}", "telnet connect") from err _LOGGER.debug("%s: telnet connection complete", self.host) self._protocol = cast(DenonAVRTelnetProtocol, transport_protocol[1]) self._connection_enabled = True @@ -572,7 +570,7 @@ def register_callback( """Register a callback handler for an event type.""" # Validate the passed in type if event != ALL_TELNET_EVENTS and event not in TELNET_EVENTS: - raise ValueError("{} is not a valid callback type.".format(event)) + raise ValueError(f"{event} is not a valid callback type.") if event not in self._callbacks.keys(): self._callbacks[event] = [] @@ -671,7 +669,7 @@ def send_commands(self, *commands: str) -> bool: if not self.healthy: return False for command in commands: - self._protocol.write("{}\r".format(command)) + self._protocol.write(f"{command}\r") return True ############## diff --git a/denonavr/audyssey.py b/denonavr/audyssey.py index a48e3fc..47819ae 100644 --- a/denonavr/audyssey.py +++ b/denonavr/audyssey.py @@ -129,13 +129,9 @@ async def _async_set_audyssey(self, cmd: AppCommandCmd) -> None: try: if res.find("cmd").text != "OK": - raise AvrProcessingError( - "SetAudyssey command {} failed".format(cmd.name) - ) + raise AvrProcessingError(f"SetAudyssey command {cmd.name} failed") except AttributeError as err: - raise AvrProcessingError( - "SetAudyssey command {} failed".format(cmd.name) - ) from err + raise AvrProcessingError(f"SetAudyssey command {cmd.name} failed") from err ############## # Properties # @@ -198,7 +194,7 @@ async def async_set_multieq(self, value: str) -> None: """Set MultiEQ mode.""" setting = MULTI_EQ_MAP_LABELS.get(value) if setting is None: - raise AvrCommandError("Value {} not known for MultiEQ".format(value)) + raise AvrCommandError(f"Value {value} not known for MultiEQ") cmd = attr.evolve( AppCommands.SetAudysseyMultiEQ, param_list=(AppCommandCmdParam(name="multeq", text=setting),), @@ -214,9 +210,7 @@ async def async_set_reflevoffset(self, value: str) -> None: ) setting = REF_LVL_OFFSET_MAP_LABELS.get(value) if setting is None: - raise AvrCommandError( - "Value {} not known for Reference level offset".format(value) - ) + raise AvrCommandError(f"Value {value} not known for Reference level offset") cmd = attr.evolve( AppCommands.SetAudysseyReflevoffset, param_list=(AppCommandCmdParam(name="reflevoffset", text=setting),), @@ -227,7 +221,7 @@ async def async_set_dynamicvol(self, value: str) -> None: """Set Dynamic Volume.""" setting = DYNAMIC_VOLUME_MAP_LABELS.get(value) if setting is None: - raise AvrCommandError("Value {} not known for Dynamic Volume".format(value)) + raise AvrCommandError(f"Value {value} not known for Dynamic Volume") cmd = attr.evolve( AppCommands.SetAudysseyDynamicvol, param_list=(AppCommandCmdParam(name="dynamicvol", text=setting),), diff --git a/denonavr/decorators.py b/denonavr/decorators.py index 4f35a2c..69d5b8d 100644 --- a/denonavr/decorators.py +++ b/denonavr/decorators.py @@ -48,24 +48,18 @@ async def wrapper(*args, **kwargs): _LOGGER.debug("HTTP status error on request %s", err.request, exc_info=True) # Separate handling of 403 errors if err.response.status_code == 403: - raise AvrForbiddenError( - "HTTPStatusError: {}".format(err), err.request - ) from err - raise AvrRequestError( - "HTTPStatusError: {}".format(err), err.request - ) from err + raise AvrForbiddenError(f"HTTPStatusError: {err}", err.request) from err + raise AvrRequestError(f"HTTPStatusError: {err}", err.request) from err except httpx.TimeoutException as err: _LOGGER.debug( "HTTP timeout exception on request %s", err.request, exc_info=True ) - raise AvrTimoutError( - "TimeoutException: {}".format(err), err.request - ) from err + raise AvrTimoutError(f"TimeoutException: {err}", err.request) from err except httpx.NetworkError as err: _LOGGER.debug( "Network error exception on request %s", err.request, exc_info=True ) - raise AvrNetworkError("NetworkError: {}".format(err), err.request) from err + raise AvrNetworkError(f"NetworkError: {err}", err.request) from err except httpx.RemoteProtocolError as err: _LOGGER.debug( "Remote protocol error exception on request %s", @@ -73,7 +67,7 @@ async def wrapper(*args, **kwargs): exc_info=True, ) raise AvrInvalidResponseError( - "RemoteProtocolError: {}".format(err), err.request + f"RemoteProtocolError: {err}", err.request ) from err except ( ET.ParseError, @@ -85,7 +79,7 @@ async def wrapper(*args, **kwargs): "Defusedxml parse error on request %s", (args, kwargs), exc_info=True ) raise AvrInvalidResponseError( - "XMLParseError: {}".format(err), (args, kwargs) + f"XMLParseError: {err}", (args, kwargs) ) from err return wrapper @@ -141,13 +135,11 @@ def run_async_synchronously(async_func: Coroutine) -> Callable: def decorator(func: Callable): # Check if function is a coroutine if not inspect.iscoroutinefunction(async_func): - raise AttributeError( - "Function {} is not a coroutine function".format(async_func) - ) + raise AttributeError(f"Function {async_func} is not a coroutine function") # Check if the signature of both functions is equal if inspect.signature(func) != inspect.signature(async_func): raise AttributeError( - "Functions {} and {} have different signatures".format(func, async_func) + f"Functions {func} and {async_func} have different signatures" ) @wraps(func) diff --git a/denonavr/denonavr.py b/denonavr/denonavr.py index 04fb8b5..1bc53cc 100644 --- a/denonavr/denonavr.py +++ b/denonavr/denonavr.py @@ -124,7 +124,7 @@ def create_zones(self, add_zones): # Name either set explicitly or name of Main Zone with suffix zonename = None if zname is None and self._name is not None: - zonename = "{} {}".format(self._name, zone) + zonename = f"{self._name} {zone}" zone_device = attr.evolve(self._device, zone=zone) zone_inst = DenonAVR( host=self._host, diff --git a/denonavr/foundation.py b/denonavr/foundation.py index 9c374ce..269077c 100644 --- a/denonavr/foundation.py +++ b/denonavr/foundation.py @@ -119,7 +119,7 @@ def __attrs_post_init__(self) -> None: self.telnet_commands = ZONE3_TELNET_COMMANDS self.urls = ZONE3_URLS else: - raise ValueError("Invalid zone {}".format(self.zone)) + raise ValueError(f"Invalid zone {self.zone}") async def _async_power_callback( self, zone: str, event: str, parameter: str @@ -207,8 +207,10 @@ async def async_identify_receiver(self) -> None: except AvrRequestError as err: _LOGGER.debug( - "Request error on port %s when identifying receiver, " - "device is not a %s receivers", + ( + "Request error on port %s when identifying receiver, " + "device is not a %s receivers" + ), r_type.port, r_type.type, exc_info=err, @@ -369,9 +371,7 @@ async def async_get_device_info(self) -> None: """Get device information.""" port = DESCRIPTION_TYPES[self.receiver.type].port command = DESCRIPTION_TYPES[self.receiver.type].url - url = "http://{host}:{port}{command}".format( - host=self.api.host, port=port, command=command - ) + url = f"http://{self.api.host}:{port}{command}" device_info = None try: @@ -384,8 +384,10 @@ async def async_get_device_info(self) -> None: raise except AvrRequestError as err: _LOGGER.error( - "During DenonAVR device identification, when trying to request" - " %s the following error occurred: %s", + ( + "During DenonAVR device identification, when trying to request" + " %s the following error occurred: %s" + ), url, err, ) @@ -397,9 +399,11 @@ async def async_get_device_info(self) -> None: self.model_name = "Unknown" self.serial_number = None _LOGGER.warning( - "Unable to get device information of host %s, Device might be " - "in a corrupted state. Continuing without device information. " - "Disconnect and reconnect power to the device and try again.", + ( + "Unable to get device information of host %s, Device might be " + "in a corrupted state. Continuing without device information. " + "Disconnect and reconnect power to the device and try again." + ), self.api.host, ) return @@ -447,14 +451,12 @@ async def async_update_power_appcommand( # Search for power tag power_tag = xml.find( - "./cmd[@{attribute}='{cmd}']/{zone}".format( - attribute=APPCOMMAND_CMD_TEXT, cmd=power_appcommand.cmd_text, zone=zone - ) + f"./cmd[@{APPCOMMAND_CMD_TEXT}='{power_appcommand.cmd_text}']/{zone}" ) if power_tag is None: raise AvrProcessingError( - "Power attribute of zone {} not found on update".format(self.zone) + f"Power attribute of zone {self.zone} not found on update" ) self._power = power_tag.text @@ -468,7 +470,7 @@ async def async_update_power_status_xml( if self.zone == MAIN_ZONE: urls.append(self.urls.mainzone) else: - urls.append("{}?ZoneName={}".format(self.urls.mainzone, self.zone)) + urls.append(f"{self.urls.mainzone}?ZoneName={self.zone}") # Tags in XML which might contain information about zones power status # ordered by their priority tags = ["./ZonePower/value", "./Power/value"] @@ -490,7 +492,7 @@ async def async_update_power_status_xml( return raise AvrProcessingError( - "Power attribute of zone {} not found on update".format(self.zone) + f"Power attribute of zone {self.zone} not found on update" ) ############## @@ -617,9 +619,8 @@ async def async_update_attrs_appcommand( # Check if each attribute was updated if update_attrs and not ignore_missing_response: raise AvrProcessingError( - "Some attributes of zone {} not found on update: {}".format( - self._device.zone, update_attrs - ) + f"Some attributes of zone {self._device.zone} not found on update:" + f" {update_attrs}" ) if update_attrs and ignore_missing_response: _LOGGER.debug( @@ -685,9 +686,8 @@ async def async_update_attrs_status_xml( # Check if each attribute was updated if update_attrs and not ignore_missing_response: raise AvrProcessingError( - "Some attributes of zone {} not found on update: {}".format( - self._device.zone, update_attrs - ) + f"Some attributes of zone {self._device.zone} not found on update:" + f" {update_attrs}" ) @staticmethod @@ -701,17 +701,15 @@ def create_appcommand_search_strings( string = "./cmd" # Text of cmd tag in query was added as attribute to response if app_command_cmd.cmd_text: - string = string + "[@{}='{}']".format( - APPCOMMAND_CMD_TEXT, app_command_cmd.cmd_text + string = ( + string + f"[@{APPCOMMAND_CMD_TEXT}='{app_command_cmd.cmd_text}']" ) # Text of name tag in query was added as attribute to response if app_command_cmd.name: - string = string + "[@{}='{}']".format( - APPCOMMAND_NAME, app_command_cmd.name - ) + string = string + f"[@{APPCOMMAND_NAME}='{app_command_cmd.name}']" # Some results include a zone tag if resp.add_zone: - string = string + "/{}".format(zone) + string = string + f"/{zone}" # Suffix like /status, /volume string = string + resp.suffix diff --git a/denonavr/input.py b/denonavr/input.py index 516e4be..33cd80c 100644 --- a/denonavr/input.py +++ b/denonavr/input.py @@ -330,7 +330,7 @@ async def _async_tuner_callback( if parameter.startswith("ANNAME"): self._station = parameter[6:] elif len(parameter) == 8: - self._frequency = "{}.{}".format(parameter[2:6], parameter[6:]).strip("0") + self._frequency = f"{parameter[2:6]}.{parameter[6:]}".strip("0") if parameter[2:] > "050000": self._band = "AM" else: @@ -484,9 +484,8 @@ async def async_get_changed_sources_appcommand( raise for child in xml.findall( - "./cmd[@{attribute}='{cmd}']/functionrename/list".format( - attribute=APPCOMMAND_CMD_TEXT, cmd=AppCommands.GetRenameSource.cmd_text - ) + f"./cmd[@{APPCOMMAND_CMD_TEXT}='{AppCommands.GetRenameSource.cmd_text}']" + "/functionrename/list" ): try: renamed_sources[child.find("name").text.strip()] = child.find( @@ -496,9 +495,8 @@ async def async_get_changed_sources_appcommand( continue for child in xml.findall( - "./cmd[@{attribute}='{cmd}']/functiondelete/list".format( - attribute=APPCOMMAND_CMD_TEXT, cmd=AppCommands.GetDeletedSource.cmd_text - ) + f"./cmd[@{APPCOMMAND_CMD_TEXT}='{AppCommands.GetDeletedSource.cmd_text}']" + "/functiondelete/list" ): try: deleted_sources[child.find("FuncName").text.strip()] = ( @@ -541,9 +539,8 @@ async def async_get_changed_sources_status_xml( ) else: raise AvrProcessingError( - "Method does not work for receiver type {}".format( - self._device.receiver.type - ) + "Method does not work for receiver type" + f" {self._device.receiver.type}" ) except AvrRequestError as err: _LOGGER.debug("Error when getting changed sources", exc_info=err) @@ -995,7 +992,7 @@ async def async_set_input_func(self, input_func: str) -> None: linp = self._input_func_map[input_func] except KeyError as err: raise AvrCommandError( - "No mapping for input source {}".format(input_func) + f"No mapping for input source {input_func}" ) from err # Create command URL and send command via HTTP GET if linp in self._favorite_func_list: diff --git a/denonavr/ssdp.py b/denonavr/ssdp.py index 6420edc..5255eff 100755 --- a/denonavr/ssdp.py +++ b/denonavr/ssdp.py @@ -35,14 +35,14 @@ SSDP_LOCATION_PATTERN = re.compile(r"(?<=LOCATION:\s).+?(?=\r)") SCPD_XMLNS = "{urn:schemas-upnp-org:device-1-0}" -SCPD_DEVICE = "{xmlns}device".format(xmlns=SCPD_XMLNS) -SCPD_DEVICELIST = "{xmlns}deviceList".format(xmlns=SCPD_XMLNS) -SCPD_DEVICETYPE = "{xmlns}deviceType".format(xmlns=SCPD_XMLNS) -SCPD_MANUFACTURER = "{xmlns}manufacturer".format(xmlns=SCPD_XMLNS) -SCPD_MODELNAME = "{xmlns}modelName".format(xmlns=SCPD_XMLNS) -SCPD_SERIALNUMBER = "{xmlns}serialNumber".format(xmlns=SCPD_XMLNS) -SCPD_FRIENDLYNAME = "{xmlns}friendlyName".format(xmlns=SCPD_XMLNS) -SCPD_PRESENTATIONURL = "{xmlns}presentationURL".format(xmlns=SCPD_XMLNS) +SCPD_DEVICE = f"{SCPD_XMLNS}device" +SCPD_DEVICELIST = f"{SCPD_XMLNS}deviceList" +SCPD_DEVICETYPE = f"{SCPD_XMLNS}deviceType" +SCPD_MANUFACTURER = f"{SCPD_XMLNS}manufacturer" +SCPD_MODELNAME = f"{SCPD_XMLNS}modelName" +SCPD_SERIALNUMBER = f"{SCPD_XMLNS}serialNumber" +SCPD_FRIENDLYNAME = f"{SCPD_XMLNS}friendlyName" +SCPD_PRESENTATIONURL = f"{SCPD_XMLNS}presentationURL" SUPPORTED_DEVICETYPES = [ "urn:schemas-upnp-org:device:MediaRenderer:1", @@ -57,10 +57,10 @@ def ssdp_request(ssdp_st: str, ssdp_mx: float = SSDP_MX) -> bytes: return "\r\n".join( [ "M-SEARCH * HTTP/1.1", - "ST: {}".format(ssdp_st), - "MX: {:d}".format(ssdp_mx), + f"ST: {ssdp_st}", + f"MX: {ssdp_mx:d}", 'MAN: "ssdp:discover"', - "HOST: {}:{}".format(*SSDP_TARGET), + f"HOST: {SSDP_ADDR}:{SSDP_PORT}", "", "", ] diff --git a/denonavr/tonecontrol.py b/denonavr/tonecontrol.py index 1eecfa2..edcde2b 100644 --- a/denonavr/tonecontrol.py +++ b/denonavr/tonecontrol.py @@ -69,10 +69,10 @@ async def _async_sound_detail_callback( if parameter[0:3] == "BAS": self._bass = int(parameter[4:]) - self._bass_level = "{}dB".format(self._bass - 50) + self._bass_level = f"{self._bass - 50}dB" elif parameter[0:3] == "TRE": self._treble = int(parameter[4:]) - self._treble_level = "{}dB".format(self._treble - 50) + self._treble_level = f"{self._treble - 50}dB" elif parameter == "TONE CTRL OFF": self._tone_control_adjust = False self._tone_control_status = False diff --git a/denonavr/volume.py b/denonavr/volume.py index 8d3963b..3e44e9b 100644 --- a/denonavr/volume.py +++ b/denonavr/volume.py @@ -169,7 +169,7 @@ async def async_set_volume(self, volume: float) -> None: Minimum is -80.0, maximum at 18.0 """ if volume < -80 or volume > 18: - raise AvrCommandError("Invalid volume: {}".format(volume)) + raise AvrCommandError(f"Invalid volume: {volume}") # Round volume because only values which are a multi of 0.5 are working volume = round(volume * 2) / 2.0 diff --git a/tests/test_denonavr.py b/tests/test_denonavr.py index f235554..3ad7be2 100644 --- a/tests/test_denonavr.py +++ b/tests/test_denonavr.py @@ -70,9 +70,7 @@ def get_sample_content(filename): """Return sample content form file.""" - with open( - "tests/xml/{filename}".format(filename=filename), encoding="utf-8" - ) as file: + with open(f"tests/xml/{filename}", encoding="utf-8") as file: return file.read() @@ -93,50 +91,36 @@ def custom_matcher(self, request: httpx.Request, *args, **kwargs): try: if request.url.path == STATUS_URL: content = get_sample_content( - "{receiver}-formMainZone_MainZoneXmlStatus{port}" - ".xml".format(receiver=self.testing_receiver, port=port_suffix) + f"{self.testing_receiver}-formMainZone_MainZoneXmlStatus" + f"{port_suffix}.xml" ) elif request.url.path == STATUS_Z2_URL: content = get_sample_content( - "{receiver}-formZone2_Zone2XmlStatus{port}.xml".format( - receiver=self.testing_receiver, port=port_suffix - ) + f"{self.testing_receiver}-formZone2_Zone2XmlStatus{port_suffix}.xml" ) elif request.url.path == STATUS_Z3_URL: content = get_sample_content( - "{receiver}-formZone3_Zone3XmlStatus{port}.xml".format( - receiver=self.testing_receiver, port=port_suffix - ) + f"{self.testing_receiver}-formZone3_Zone3XmlStatus{port_suffix}.xml" ) elif request.url.path == MAINZONE_URL: content = get_sample_content( - "{receiver}-formMainZone_MainZoneXml{port}.xml".format( - receiver=self.testing_receiver, port=port_suffix - ) + f"{self.testing_receiver}-formMainZone_MainZoneXml{port_suffix}.xml" ) elif request.url.path == DEVICEINFO_URL: content = get_sample_content( - "{receiver}-Deviceinfo{port}.xml".format( - receiver=self.testing_receiver, port=port_suffix - ) + f"{self.testing_receiver}-Deviceinfo{port_suffix}.xml" ) elif request.url.path == NETAUDIOSTATUS_URL: content = get_sample_content( - "{receiver}-formNetAudio_StatusXml{port}.xml".format( - receiver=self.testing_receiver, port=port_suffix - ) + f"{self.testing_receiver}-formNetAudio_StatusXml{port_suffix}.xml" ) elif request.url.path == TUNERSTATUS_URL: content = get_sample_content( - "{receiver}-formTuner_TunerXml{port}.xml".format( - receiver=self.testing_receiver, port=port_suffix - ) + f"{self.testing_receiver}-formTuner_TunerXml{port_suffix}.xml" ) elif request.url.path == HDTUNERSTATUS_URL: content = get_sample_content( - "{receiver}-formTuner_HdXml{port}.xml".format( - receiver=self.testing_receiver, port=port_suffix - ) + f"{self.testing_receiver}-formTuner_HdXml{port_suffix}.xml" ) elif request.url.path == APPCOMMAND_URL: content_str = request.read().decode("utf-8") @@ -145,9 +129,7 @@ def custom_matcher(self, request: httpx.Request, *args, **kwargs): else: ep_suffix = "-update" content = get_sample_content( - "{receiver}-AppCommand{ep}{port}.xml".format( - receiver=self.testing_receiver, port=port_suffix, ep=ep_suffix - ) + f"{self.testing_receiver}-AppCommand{ep_suffix}{port_suffix}.xml" ) elif request.url.path in [DESCRIPTION_URL1, DESCRIPTION_URL2]: content = get_sample_content("AVR-X1600H_upnp.xml") @@ -171,20 +153,18 @@ async def test_receiver_type(self, httpx_mock: HTTPXMock): """Check that receiver type is determined correctly.""" httpx_mock.add_callback(self.custom_matcher) for receiver, spec in TESTING_RECEIVERS.items(): - print("Receiver: {}".format(receiver)) + print(f"Receiver: {receiver}") # Switch receiver and update to load new sample files self.testing_receiver = receiver self.denon = denonavr.DenonAVR(FAKE_IP, add_zones=spec[0]) await self.denon.async_setup() - assert ( - self.denon.receiver_type == spec[1].type - ), "Receiver type is {} not {} for receiver {}".format( - self.denon.receiver_type, spec[1].type, receiver + assert self.denon.receiver_type == spec[1].type, ( + f"Receiver type is {self.denon.receiver_type} not {spec[1].type} for" + f" receiver {receiver}" ) - assert ( - self.denon.receiver_port == spec[1].port - ), "Receiver port is {} not {} for receiver {}".format( - self.denon.receiver_port, spec[1].port, receiver + assert self.denon.receiver_port == spec[1].port, ( + f"Receiver port is {self.denon.receiver_port} not {spec[1].port} for" + f" receiver {receiver}" ) @pytest.mark.asyncio @@ -197,7 +177,7 @@ async def test_input_func_switch(self, httpx_mock: HTTPXMock): self.denon = denonavr.DenonAVR(FAKE_IP, add_zones=spec[0]) # Switch through all functions and check if successful for name, zone in self.denon.zones.items(): - print("Receiver: {}, Zone: {}".format(receiver, name)) + print(f"Receiver: {receiver}, Zone: {name}") await self.denon.zones[name].async_update() assert len(zone.input_func_list) > 0 for input_func in zone.input_func_list: @@ -208,24 +188,22 @@ async def test_attributes_not_none(self, httpx_mock: HTTPXMock): """Check that certain attributes are not None.""" httpx_mock.add_callback(self.custom_matcher) for receiver, spec in TESTING_RECEIVERS.items(): - print("Receiver: {}".format(receiver)) + print(f"Receiver: {receiver}") # Switch receiver and update to load new sample files self.testing_receiver = receiver self.denon = denonavr.DenonAVR(FAKE_IP, add_zones=spec[0]) await self.denon.async_setup() - assert self.denon.name is not None, "Name is None for receiver {}".format( - receiver - ) + assert self.denon.name is not None, f"Name is None for receiver {receiver}" assert ( self.denon.support_sound_mode is not None - ), "support_sound_mode is None for receiver {}".format(receiver) + ), f"support_sound_mode is None for receiver {receiver}" await self.denon.async_update() assert ( self.denon.power is not None - ), "Power status is None for receiver {}".format(receiver) - assert self.denon.state is not None, "State is None for receiver {}".format( - receiver - ) + ), f"Power status is None for receiver {receiver}" + assert ( + self.denon.state is not None + ), f"State is None for receiver {receiver}" @pytest.mark.asyncio async def test_sound_mode(self, httpx_mock: HTTPXMock): @@ -237,7 +215,7 @@ async def test_sound_mode(self, httpx_mock: HTTPXMock): self.denon = denonavr.DenonAVR(FAKE_IP, add_zones=spec[0]) # Switch through all functions and check if successful for name in self.denon.zones: - print("Receiver: {}, Zone: {}".format(receiver, name)) + print(f"Receiver: {receiver}, Zone: {name}") await self.denon.zones[name].async_update() support_sound_mode = self.denon.zones[name].support_sound_mode sound_mode = self.denon.zones[name].sound_mode diff --git a/tests/test_ssdp.py b/tests/test_ssdp.py index 6516b38..024d4e9 100644 --- a/tests/test_ssdp.py +++ b/tests/test_ssdp.py @@ -9,9 +9,7 @@ def get_sample_content(filename): """Return sample content form file.""" - with open( - "tests/xml/{filename}".format(filename=filename), encoding="utf-8" - ) as file: + with open(f"tests/xml/{filename}", encoding="utf-8") as file: return file.read() @@ -33,6 +31,6 @@ def get_sample_content(filename): def test_evaluate(model, expected_device): """Test that the discovered device looks like expected.""" url = "https://10.0.0.0/denon" - body = get_sample_content("{model}_upnp.xml".format(model=model)) + body = get_sample_content(f"{model}_upnp.xml") device = evaluate_scpd_xml(url, body) assert device == expected_device