Small code style improvements to Alexa integration (#33660)
This commit is contained in:
parent
db72039b8f
commit
feed139ae7
5 changed files with 34 additions and 37 deletions
|
@ -734,12 +734,11 @@ class AlexaPlaybackController(AlexaCapability):
|
|||
media_player.SUPPORT_STOP: "Stop",
|
||||
}
|
||||
|
||||
supported_operations = []
|
||||
for operation in operations:
|
||||
if operation & supported_features:
|
||||
supported_operations.append(operations[operation])
|
||||
|
||||
return supported_operations
|
||||
return [
|
||||
value
|
||||
for operation, value in operations.items()
|
||||
if operation & supported_features
|
||||
]
|
||||
|
||||
|
||||
class AlexaInputController(AlexaCapability):
|
||||
|
@ -759,9 +758,7 @@ class AlexaInputController(AlexaCapability):
|
|||
source_list = self.entity.attributes.get(
|
||||
media_player.ATTR_INPUT_SOURCE_LIST, []
|
||||
)
|
||||
input_list = AlexaInputController.get_valid_inputs(source_list)
|
||||
|
||||
return input_list
|
||||
return AlexaInputController.get_valid_inputs(source_list)
|
||||
|
||||
@staticmethod
|
||||
def get_valid_inputs(source_list):
|
||||
|
@ -1829,10 +1826,11 @@ class AlexaEqualizerController(AlexaCapability):
|
|||
configurations = None
|
||||
sound_mode_list = self.entity.attributes.get(media_player.ATTR_SOUND_MODE_LIST)
|
||||
if sound_mode_list:
|
||||
supported_sound_modes = []
|
||||
for sound_mode in sound_mode_list:
|
||||
if sound_mode.upper() in ("MOVIE", "MUSIC", "NIGHT", "SPORT", "TV"):
|
||||
supported_sound_modes.append({"name": sound_mode.upper()})
|
||||
supported_sound_modes = [
|
||||
{"name": sound_mode.upper()}
|
||||
for sound_mode in sound_mode_list
|
||||
if sound_mode.upper() in ("MOVIE", "MUSIC", "NIGHT", "SPORT", "TV")
|
||||
]
|
||||
|
||||
configurations = {"modes": {"supported": supported_sound_modes}}
|
||||
|
||||
|
@ -1890,7 +1888,7 @@ class AlexaCameraStreamController(AlexaCapability):
|
|||
|
||||
def camera_stream_configurations(self):
|
||||
"""Return cameraStreamConfigurations object."""
|
||||
camera_stream_configurations = [
|
||||
return [
|
||||
{
|
||||
"protocols": ["HLS"],
|
||||
"resolutions": [{"width": 1280, "height": 720}],
|
||||
|
@ -1899,4 +1897,3 @@ class AlexaCameraStreamController(AlexaCapability):
|
|||
"audioCodecs": ["AAC"],
|
||||
}
|
||||
]
|
||||
return camera_stream_configurations
|
||||
|
|
|
@ -268,8 +268,7 @@ class AlexaEntity:
|
|||
if not interface.properties_proactively_reported():
|
||||
continue
|
||||
|
||||
for prop in interface.serialize_properties():
|
||||
yield prop
|
||||
yield from interface.serialize_properties()
|
||||
|
||||
def serialize_discovery(self):
|
||||
"""Serialize the entity for discovery."""
|
||||
|
@ -283,10 +282,12 @@ class AlexaEntity:
|
|||
}
|
||||
|
||||
locale = self.config.locale
|
||||
capabilities = []
|
||||
for i in self.interfaces():
|
||||
if locale in i.supported_locales:
|
||||
capabilities.append(i.serialize_discovery())
|
||||
capabilities = [
|
||||
i.serialize_discovery()
|
||||
for i in self.interfaces()
|
||||
if locale in i.supported_locales
|
||||
]
|
||||
|
||||
result["capabilities"] = capabilities
|
||||
|
||||
return result
|
||||
|
|
|
@ -355,7 +355,6 @@ async def async_api_deactivate(hass, config, directive, context):
|
|||
async def async_api_set_percentage(hass, config, directive, context):
|
||||
"""Process a set percentage request."""
|
||||
entity = directive.entity
|
||||
percentage = int(directive.payload["percentage"])
|
||||
service = None
|
||||
data = {ATTR_ENTITY_ID: entity.entity_id}
|
||||
|
||||
|
@ -363,6 +362,7 @@ async def async_api_set_percentage(hass, config, directive, context):
|
|||
service = fan.SERVICE_SET_SPEED
|
||||
speed = "off"
|
||||
|
||||
percentage = int(directive.payload["percentage"])
|
||||
if percentage <= 33:
|
||||
speed = "low"
|
||||
elif percentage <= 66:
|
||||
|
@ -568,7 +568,7 @@ async def async_api_adjust_volume_step(hass, config, directive, context):
|
|||
|
||||
data = {ATTR_ENTITY_ID: entity.entity_id}
|
||||
|
||||
for _ in range(0, abs(volume_int)):
|
||||
for _ in range(abs(volume_int)):
|
||||
await hass.services.async_call(
|
||||
entity.domain, service_volume, data, blocking=False, context=context
|
||||
)
|
||||
|
@ -849,7 +849,6 @@ async def async_api_reportstate(hass, config, directive, context):
|
|||
async def async_api_set_power_level(hass, config, directive, context):
|
||||
"""Process a SetPowerLevel request."""
|
||||
entity = directive.entity
|
||||
percentage = int(directive.payload["powerLevel"])
|
||||
service = None
|
||||
data = {ATTR_ENTITY_ID: entity.entity_id}
|
||||
|
||||
|
@ -857,6 +856,7 @@ async def async_api_set_power_level(hass, config, directive, context):
|
|||
service = fan.SERVICE_SET_SPEED
|
||||
speed = "off"
|
||||
|
||||
percentage = int(directive.payload["powerLevel"])
|
||||
if percentage <= 33:
|
||||
speed = "low"
|
||||
elif percentage <= 66:
|
||||
|
@ -920,10 +920,10 @@ async def async_api_arm(hass, config, directive, context):
|
|||
|
||||
if arm_state == "ARMED_AWAY":
|
||||
service = SERVICE_ALARM_ARM_AWAY
|
||||
if arm_state == "ARMED_STAY":
|
||||
service = SERVICE_ALARM_ARM_HOME
|
||||
if arm_state == "ARMED_NIGHT":
|
||||
elif arm_state == "ARMED_NIGHT":
|
||||
service = SERVICE_ALARM_ARM_NIGHT
|
||||
elif arm_state == "ARMED_STAY":
|
||||
service = SERVICE_ALARM_ARM_HOME
|
||||
|
||||
await hass.services.async_call(
|
||||
entity.domain, service, data, blocking=False, context=context
|
||||
|
@ -1383,7 +1383,7 @@ async def async_api_skipchannel(hass, config, directive, context):
|
|||
else:
|
||||
service_media = SERVICE_MEDIA_NEXT_TRACK
|
||||
|
||||
for _ in range(0, abs(channel)):
|
||||
for _ in range(abs(channel)):
|
||||
await hass.services.async_call(
|
||||
entity.domain, service_media, data, blocking=False, context=context
|
||||
)
|
||||
|
|
|
@ -201,7 +201,7 @@ def resolve_slot_synonyms(key, request):
|
|||
_LOGGER.debug(
|
||||
"Found multiple synonym resolutions for slot value: {%s: %s}",
|
||||
key,
|
||||
request["value"],
|
||||
resolved_value,
|
||||
)
|
||||
|
||||
return resolved_value
|
||||
|
|
|
@ -296,14 +296,13 @@ class AlexaPresetResource(AlexaCapabilityResource):
|
|||
configuration["unitOfMeasure"] = self._unit_of_measure
|
||||
|
||||
if self._presets:
|
||||
preset_resources = []
|
||||
for preset in self._presets:
|
||||
preset_resources.append(
|
||||
{
|
||||
"rangeValue": preset["value"],
|
||||
"presetResources": self.serialize_labels(preset["labels"]),
|
||||
}
|
||||
)
|
||||
preset_resources = [
|
||||
{
|
||||
"rangeValue": preset["value"],
|
||||
"presetResources": self.serialize_labels(preset["labels"]),
|
||||
}
|
||||
for preset in self._presets
|
||||
]
|
||||
configuration["presets"] = preset_resources
|
||||
|
||||
return configuration
|
||||
|
|
Loading…
Add table
Reference in a new issue