Skip to content

Commit

Permalink
Cleanup unused AlexaPercentageController code (#82880)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbouwh authored and marcelveldt committed Nov 30, 2022
1 parent c4d55ab commit 53c4b82
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 124 deletions.
4 changes: 2 additions & 2 deletions CODEOWNERS
Validating CODEOWNERS rules …
Expand Up @@ -63,8 +63,8 @@ build.json @home-assistant/supervisor
/tests/components/alarm_control_panel/ @home-assistant/core
/homeassistant/components/alert/ @home-assistant/core @frenck
/tests/components/alert/ @home-assistant/core @frenck
/homeassistant/components/alexa/ @home-assistant/cloud @ochlocracy
/tests/components/alexa/ @home-assistant/cloud @ochlocracy
/homeassistant/components/alexa/ @home-assistant/cloud @ochlocracy @jbouwh
/tests/components/alexa/ @home-assistant/cloud @ochlocracy @jbouwh
/homeassistant/components/almond/ @gcampax @balloob
/tests/components/almond/ @gcampax @balloob
/homeassistant/components/amberelectric/ @madpilot
Expand Down
53 changes: 0 additions & 53 deletions homeassistant/components/alexa/capabilities.py
Expand Up @@ -656,59 +656,6 @@ def get_property(self, name):
return None


class AlexaPercentageController(AlexaCapability):
"""Implements Alexa.PercentageController.
https://developer.amazon.com/docs/device-apis/alexa-percentagecontroller.html
"""

supported_locales = {
"de-DE",
"en-AU",
"en-CA",
"en-GB",
"en-IN",
"en-US",
"es-ES",
"es-US",
"fr-CA",
"fr-FR",
"hi-IN",
"it-IT",
"ja-JP",
"pt-BR",
}

def name(self):
"""Return the Alexa API name of this interface."""
return "Alexa.PercentageController"

def properties_supported(self):
"""Return what properties this entity supports."""
return [{"name": "percentage"}]

def properties_proactively_reported(self):
"""Return True if properties asynchronously reported."""
return True

def properties_retrievable(self):
"""Return True if properties can be retrieved."""
return True

def get_property(self, name):
"""Read and return a property."""
if name != "percentage":
raise UnsupportedProperty(name)

if self.entity.domain == fan.DOMAIN:
return self.entity.attributes.get(fan.ATTR_PERCENTAGE) or 0

if self.entity.domain == cover.DOMAIN:
return self.entity.attributes.get(cover.ATTR_CURRENT_POSITION, 0)

return 0


class AlexaSpeaker(AlexaCapability):
"""Implements Alexa.Speaker.
Expand Down
68 changes: 0 additions & 68 deletions homeassistant/components/alexa/handlers.py
Expand Up @@ -443,74 +443,6 @@ async def async_api_deactivate(
)


@HANDLERS.register(("Alexa.PercentageController", "SetPercentage"))
async def async_api_set_percentage(
hass: ha.HomeAssistant,
config: AbstractConfig,
directive: AlexaDirective,
context: ha.Context,
) -> AlexaResponse:
"""Process a set percentage request."""
entity = directive.entity

if entity.domain == fan.DOMAIN:
percentage = int(directive.payload["percentage"])
service = fan.SERVICE_SET_PERCENTAGE
data = {
ATTR_ENTITY_ID: entity.entity_id,
fan.ATTR_PERCENTAGE: percentage,
}

await hass.services.async_call(
entity.domain, service, data, blocking=False, context=context
)
elif entity.domain == humidifier.DOMAIN:
percentage = int(directive.payload["percentage"])
service = humidifier.SERVICE_SET_HUMIDITY
data = {
ATTR_ENTITY_ID: entity.entity_id,
humidifier.ATTR_HUMIDITY: percentage,
}

await hass.services.async_call(
entity.domain, service, data, blocking=False, context=context
)
else:
raise AlexaInvalidDirectiveError(DIRECTIVE_NOT_SUPPORTED)

return directive.response()


@HANDLERS.register(("Alexa.PercentageController", "AdjustPercentage"))
async def async_api_adjust_percentage(
hass: ha.HomeAssistant,
config: AbstractConfig,
directive: AlexaDirective,
context: ha.Context,
) -> AlexaResponse:
"""Process an adjust percentage request."""
entity = directive.entity

if entity.domain != fan.DOMAIN:
raise AlexaInvalidDirectiveError(DIRECTIVE_NOT_SUPPORTED)

percentage_delta = int(directive.payload["percentageDelta"])
current = entity.attributes.get(fan.ATTR_PERCENTAGE) or 0
# set percentage
percentage = min(100, max(0, percentage_delta + current))
service = fan.SERVICE_SET_PERCENTAGE
data = {
ATTR_ENTITY_ID: entity.entity_id,
fan.ATTR_PERCENTAGE: percentage,
}

await hass.services.async_call(
entity.domain, service, data, blocking=False, context=context
)

return directive.response()


@HANDLERS.register(("Alexa.LockController", "Lock"))
async def async_api_lock(
hass: ha.HomeAssistant,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/alexa/manifest.json
Expand Up @@ -4,6 +4,6 @@
"documentation": "https://www.home-assistant.io/integrations/alexa",
"dependencies": ["http"],
"after_dependencies": ["camera"],
"codeowners": ["@home-assistant/cloud", "@ochlocracy"],
"codeowners": ["@home-assistant/cloud", "@ochlocracy", "@jbouwh"],
"iot_class": "cloud_push"
}

0 comments on commit 53c4b82

Please sign in to comment.