From fcccc44ccbf8880acbf5d8a4135d68f96e408a04 Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Tue, 29 Nov 2022 10:06:53 +0100 Subject: [PATCH] Cleanup unused AlexaPercentageController code (#82880) --- CODEOWNERS | 4 +- .../components/alexa/capabilities.py | 53 --------------- homeassistant/components/alexa/handlers.py | 68 ------------------- homeassistant/components/alexa/manifest.json | 2 +- 4 files changed, 3 insertions(+), 124 deletions(-) diff --git a/CODEOWNERS b/CODEOWNERS index 51a2c5c6db2..78ab439cf7e 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -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 diff --git a/homeassistant/components/alexa/capabilities.py b/homeassistant/components/alexa/capabilities.py index f54f66b814c..56b9e88e27e 100644 --- a/homeassistant/components/alexa/capabilities.py +++ b/homeassistant/components/alexa/capabilities.py @@ -656,59 +656,6 @@ class AlexaColorTemperatureController(AlexaCapability): 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. diff --git a/homeassistant/components/alexa/handlers.py b/homeassistant/components/alexa/handlers.py index 3f816501cf3..d9a2e7016e9 100644 --- a/homeassistant/components/alexa/handlers.py +++ b/homeassistant/components/alexa/handlers.py @@ -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, diff --git a/homeassistant/components/alexa/manifest.json b/homeassistant/components/alexa/manifest.json index 486079b0313..d73fc3590bd 100644 --- a/homeassistant/components/alexa/manifest.json +++ b/homeassistant/components/alexa/manifest.json @@ -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" }