Code style improvements [alexa] (#83258)

This commit is contained in:
Marc Mueller 2022-12-05 09:36:03 +01:00 committed by GitHub
parent 7e2960a973
commit 1f30d761a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -169,60 +169,47 @@ class AlexaCapability:
def serialize_discovery(self): def serialize_discovery(self):
"""Serialize according to the Discovery API.""" """Serialize according to the Discovery API."""
# pylint: disable=assignment-from-none
# Methods may be overridden and return a value.
result = {"type": "AlexaInterface", "interface": self.name(), "version": "3"} result = {"type": "AlexaInterface", "interface": self.name(), "version": "3"}
if (instance := self.instance) is not None: if (instance := self.instance) is not None:
result["instance"] = instance result["instance"] = instance
properties_supported = self.properties_supported() if properties_supported := self.properties_supported():
if properties_supported:
result["properties"] = { result["properties"] = {
"supported": self.properties_supported(), "supported": properties_supported,
"proactivelyReported": self.properties_proactively_reported(), "proactivelyReported": self.properties_proactively_reported(),
"retrievable": self.properties_retrievable(), "retrievable": self.properties_retrievable(),
} }
proactively_reported = self.capability_proactively_reported() if (proactively_reported := self.capability_proactively_reported()) is not None:
if proactively_reported is not None:
result["proactivelyReported"] = proactively_reported result["proactivelyReported"] = proactively_reported
non_controllable = self.properties_non_controllable() if (non_controllable := self.properties_non_controllable()) is not None:
if non_controllable is not None:
result["properties"]["nonControllable"] = non_controllable result["properties"]["nonControllable"] = non_controllable
supports_deactivation = self.supports_deactivation() if (supports_deactivation := self.supports_deactivation()) is not None:
if supports_deactivation is not None:
result["supportsDeactivation"] = supports_deactivation result["supportsDeactivation"] = supports_deactivation
capability_resources = self.capability_resources() if capability_resources := self.capability_resources():
if capability_resources:
result["capabilityResources"] = capability_resources result["capabilityResources"] = capability_resources
configuration = self.configuration() if configuration := self.configuration():
if configuration:
result["configuration"] = configuration result["configuration"] = configuration
# The plural configurations object is different than the singular configuration object above. # The plural configurations object is different than the singular configuration object above.
configurations = self.configurations() if configurations := self.configurations():
if configurations:
result["configurations"] = configurations result["configurations"] = configurations
semantics = self.semantics() if semantics := self.semantics():
if semantics:
result["semantics"] = semantics result["semantics"] = semantics
supported_operations = self.supported_operations() if supported_operations := self.supported_operations():
if supported_operations:
result["supportedOperations"] = supported_operations result["supportedOperations"] = supported_operations
inputs = self.inputs() if inputs := self.inputs():
if inputs:
result["inputs"] = inputs result["inputs"] = inputs
camera_stream_configurations = self.camera_stream_configurations() if camera_stream_configurations := self.camera_stream_configurations():
if camera_stream_configurations:
result["cameraStreamConfigurations"] = camera_stream_configurations result["cameraStreamConfigurations"] = camera_stream_configurations
return result return result