From 3ed71412d48922a79c773d4a0ca7dc3d6e33f7ec Mon Sep 17 00:00:00 2001 From: Jonh Sady Date: Tue, 18 Feb 2025 18:38:43 -0300 Subject: [PATCH] adjustments for colaborator --- homeassistant/components/redgtech/__init__.py | 5 ++ .../components/redgtech/config_flow.py | 34 ++++--- .../components/redgtech/manifest.json | 7 +- .../components/redgtech/quality_scale.yaml | 12 +-- .../components/redgtech/services.yaml | 0 .../components/redgtech/strings.json | 88 +++++-------------- homeassistant/components/redgtech/switch.py | 12 ++- requirements_all.txt | 2 +- 8 files changed, 65 insertions(+), 95 deletions(-) delete mode 100644 homeassistant/components/redgtech/services.yaml diff --git a/homeassistant/components/redgtech/__init__.py b/homeassistant/components/redgtech/__init__.py index 568d8db2f6f..6a04f2b3d79 100644 --- a/homeassistant/components/redgtech/__init__.py +++ b/homeassistant/components/redgtech/__init__.py @@ -4,9 +4,14 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform from .const import DOMAIN from redgtech_api import RedgtechAPI +from typing import TypedDict _LOGGER = logging.getLogger(__name__) +class RedgtechEntryData(TypedDict): + config: dict + entities: list + PLATFORMS: list[Platform] = [Platform.SWITCH] async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: diff --git a/homeassistant/components/redgtech/config_flow.py b/homeassistant/components/redgtech/config_flow.py index 7913fca4772..3374b1ccaa5 100644 --- a/homeassistant/components/redgtech/config_flow.py +++ b/homeassistant/components/redgtech/config_flow.py @@ -1,37 +1,43 @@ from homeassistant import config_entries import voluptuous as vol import logging +from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, CONF_ACCESS_TOKEN from .const import DOMAIN from redgtech_api import RedgtechAPI +from typing import Any, Dict, Optional _LOGGER = logging.getLogger(__name__) class RedgtechConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): """Config Flow for Redgtech integration.""" - VERSION = 1 - - async def async_step_user(self, user_input=None): + async def async_step_user(self, user_input: Optional[Dict[str, Any]] = None) -> config_entries.FlowResult: """Handle the initial user step for login.""" errors = {} if user_input is not None: - email = user_input.get("email") - password = user_input.get("password") - + email = user_input.get(CONF_EMAIL) + password = user_input.get(CONF_PASSWORD) api = RedgtechAPI() + try: access_token = await api.login(email, password) if access_token: - _LOGGER.info("Login successful") + _LOGGER.debug("Login successful, token received.") + + existing_entries = self._async_current_entries() + for entry in existing_entries: + if entry.data.get(CONF_ACCESS_TOKEN) == access_token: + return self.async_abort(reason="already_configured") return self.async_create_entry( title="Redgtech", - data={"access_token": access_token} + data={CONF_ACCESS_TOKEN: access_token} ) - else: - _LOGGER.error("Login failed: No access token received") - errors["base"] = "invalid_auth" + + _LOGGER.error("Login failed: No access token received") + errors["base"] = "invalid_auth" + except Exception as e: _LOGGER.error("Login failed: %s", e) errors["base"] = "cannot_connect" @@ -39,8 +45,8 @@ class RedgtechConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): return self.async_show_form( step_id="user", data_schema=vol.Schema({ - vol.Required("email"): str, - vol.Required("password"): str, + vol.Required(CONF_EMAIL): str, + vol.Required(CONF_PASSWORD): str, }), errors=errors - ) \ No newline at end of file + ) diff --git a/homeassistant/components/redgtech/manifest.json b/homeassistant/components/redgtech/manifest.json index 6afebc8e5d1..3af46a5966e 100644 --- a/homeassistant/components/redgtech/manifest.json +++ b/homeassistant/components/redgtech/manifest.json @@ -1,12 +1,11 @@ { "domain": "redgtech", "name": "Redgtech", - "codeowners": [], + "codeowners": ["@jonhsady", "@luan-nvg"], "documentation": "https://www.home-assistant.io/integrations/redgtech", "iot_class": "cloud_polling", - "logo": "/brands/redgtech/logo.png", "integration_type": "service", "config_flow": true, - "quality_scale": "silver", - "requirements": ["redgtech-api==0.1.14"] + "quality_scale": "bronze", + "requirements": ["redgtech-api==0.1.16"] } \ No newline at end of file diff --git a/homeassistant/components/redgtech/quality_scale.yaml b/homeassistant/components/redgtech/quality_scale.yaml index 7cf17253b19..fc39b919c3e 100644 --- a/homeassistant/components/redgtech/quality_scale.yaml +++ b/homeassistant/components/redgtech/quality_scale.yaml @@ -3,13 +3,9 @@ rules: action-setup: status: exempt comment: only entity actions - appropriate-polling: - status: exempt - comment: the integration does not poll + appropriate-polling: done brands: done - common-modules: - status: exempt - comment: the integration currently implements only one platform and has no coordinator + common-modules: done config-flow-test-coverage: done config-flow: done dependency-transparency: done @@ -17,9 +13,7 @@ rules: docs-high-level-description: done docs-installation-instructions: done docs-removal-instructions: done - entity-event-setup: - status: exempt - comment: the integration does not subscribe to events + entity-event-setup: done entity-unique-id: done has-entity-name: done runtime-data: done diff --git a/homeassistant/components/redgtech/services.yaml b/homeassistant/components/redgtech/services.yaml deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/homeassistant/components/redgtech/strings.json b/homeassistant/components/redgtech/strings.json index 111018f9eef..abd1961d250 100644 --- a/homeassistant/components/redgtech/strings.json +++ b/homeassistant/components/redgtech/strings.json @@ -1,67 +1,27 @@ { - "config": { - "step": { - "user": { - "title": "User Configuration", - "description": "Please enter your email address.", - "data": { - "email": "Email", - "password": "Password" - } - } + "config": { + "step": { + "user": { + "title": "User Configuration", + "description": "Please enter your email address.", + "data": { + "email": { + "label": "Email", + "description": "Enter your email address for authentication." + }, + "password": { + "label": "Password", + "description": "Enter your password for authentication." + } + }, + "errors": { + "invalid_auth": "Invalid authentication.", + "invalid_email": "Invalid email address.", + "invalid_password": "Invalid password.", + "email_required": "Email is required.", + "password_required": "Password is required." } - }, - "common": { - "generic": { - "model": "Model", - "ui_managed": "Managed via UI" - }, - "device_automation": { - "condition_type": { - "is_on": "{entity_name} is on", - "is_off": "{entity_name} is off" - }, - "extra_fields": { - "above": "Above", - "below": "Below", - "for": "Duration", - "to": "To", - "value": "Value", - "zone": "Zone" - }, - "trigger_type": { - "changed_states": "{entity_name} turned on or off", - "turned_on": "{entity_name} turned on", - "turned_off": "{entity_name} turned off" - }, - "action_type": { - "toggle": "Toggle {entity_name}", - "turn_on": "Turn on {entity_name}", - "turn_off": "Turn off {entity_name}" - } - }, - "action": { - "connect": "Connect", - "disconnect": "Disconnect", - "enable": "Enable", - "disable": "Disable", - "open": "Open", - "close": "Close", - "reload": "Reload", - "restart": "Restart", - "start": "Start", - "stop": "Stop", - "pause": "Pause", - "turn_on": "Turn on", - "turn_off": "Turn off", - "toggle": "Toggle" - }, - "time": { - "sunday": "Sunday" - }, - "state": { - "not_home": "Away" - }, - "config_flow": {} + } } - } \ No newline at end of file + } +} \ No newline at end of file diff --git a/homeassistant/components/redgtech/switch.py b/homeassistant/components/redgtech/switch.py index 68b316767d9..4407dfe6e53 100644 --- a/homeassistant/components/redgtech/switch.py +++ b/homeassistant/components/redgtech/switch.py @@ -20,10 +20,16 @@ async def async_setup_entry(hass, config_entry, async_add_entities): entities = [] if coordinator.data: + existing_entities = hass.data.get(DOMAIN, {}).get("entities", []) for item in coordinator.data.get("boards", []): - categories = item.get("displayCategories", "") - if "SWITCH" in categories: - entities.append(RedgtechSwitch(coordinator, item, api)) + entity_id = item.get("endpointId", "") + if entity_id not in existing_entities: + categories = item.get("displayCategories", "") + if "SWITCH" in categories: + entities.append(RedgtechSwitch(coordinator, item, api)) + existing_entities.append(entity_id) + + hass.data.setdefault(DOMAIN, {})["entities"] = existing_entities async_add_entities(entities) diff --git a/requirements_all.txt b/requirements_all.txt index 109daf0c4c0..7e4800daed0 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2603,7 +2603,7 @@ rapt-ble==0.1.2 raspyrfm-client==1.2.8 # homeassistant.components.redgtech -redgtech-api==0.1.14 +redgtech-api==0.1.16 # homeassistant.components.refoss refoss-ha==1.2.5