diff --git a/custom_components/mygekko/__init__.py b/custom_components/mygekko/__init__.py index 8fa8950..6bfe9e7 100644 --- a/custom_components/mygekko/__init__.py +++ b/custom_components/mygekko/__init__.py @@ -21,9 +21,11 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator from homeassistant.helpers.update_coordinator import UpdateFailed from PyMyGekko import MyGekkoApiClientBase +from PyMyGekko import MyGekkoDemoModeClient from PyMyGekko import MyGekkoLocalApiClient from PyMyGekko import MyGekkoQueryApiClient +from .const import CONF_CONNECTION_DEMO_MODE from .const import CONF_CONNECTION_LOCAL from .const import CONF_CONNECTION_MY_GEKKO_CLOUD from .const import CONF_CONNECTION_TYPE @@ -67,10 +69,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): password = entry.data.get(CONF_PASSWORD) ip_address = entry.data.get(CONF_IP_ADDRESS) - session = async_get_clientsession(hass) + session = async_get_clientsession(hass, verify_ssl=False) client = MyGekkoLocalApiClient(username, password, session, ip_address) + if entry.data.get(CONF_CONNECTION_TYPE) == CONF_CONNECTION_DEMO_MODE: + client = MyGekkoDemoModeClient() + if client is None: _LOGGER.exception("async_refresh failed: client is None") raise ConfigEntryError diff --git a/custom_components/mygekko/config_flow.py b/custom_components/mygekko/config_flow.py index 0c1aa79..3b58f6a 100644 --- a/custom_components/mygekko/config_flow.py +++ b/custom_components/mygekko/config_flow.py @@ -3,26 +3,26 @@ import homeassistant.helpers.config_validation as cv import voluptuous as vol +from aiohttp import ClientConnectorError from homeassistant import config_entries from homeassistant.const import CONF_API_KEY from homeassistant.const import CONF_IP_ADDRESS from homeassistant.const import CONF_PASSWORD from homeassistant.const import CONF_USERNAME -from homeassistant.core import callback from homeassistant.helpers.aiohttp_client import async_create_clientsession from PyMyGekko import MyGekkoLocalApiClient from PyMyGekko import MyGekkoQueryApiClient from PyMyGekko.data_provider import MyGekkoError +from .const import CONF_CONNECTION_DEMO_MODE +from .const import CONF_CONNECTION_DEMO_MODE_LABEL from .const import CONF_CONNECTION_LOCAL from .const import CONF_CONNECTION_LOCAL_LABEL from .const import CONF_CONNECTION_MY_GEKKO_CLOUD from .const import CONF_CONNECTION_MY_GEKKO_CLOUD_LABEL from .const import CONF_CONNECTION_TYPE -from .const import CONF_DEMO_MODE from .const import CONF_GEKKOID from .const import DOMAIN -from .const import PLATFORMS _LOGGER: logging.Logger = logging.getLogger(__name__) @@ -34,6 +34,7 @@ { CONF_CONNECTION_MY_GEKKO_CLOUD: CONF_CONNECTION_MY_GEKKO_CLOUD_LABEL, CONF_CONNECTION_LOCAL: CONF_CONNECTION_LOCAL_LABEL, + CONF_CONNECTION_DEMO_MODE: CONF_CONNECTION_DEMO_MODE_LABEL, } ) } @@ -77,11 +78,6 @@ async def async_step_user(self, user_input=None): return await self.async_step_connection_selection(user_input) - @staticmethod - @callback - def async_get_options_flow(config_entry): - return MyGekkoOptionsFlowHandler(config_entry) - async def async_step_connection_selection(self, user_input): """Show the configuration form to edit location data.""" _LOGGER.debug("Config flow async_step_connection_selection %s", user_input) @@ -95,6 +91,11 @@ async def async_step_connection_selection(self, user_input): if connection_type == CONF_CONNECTION_LOCAL: return await self.async_step_connection_local(user_input) + if connection_type == CONF_CONNECTION_DEMO_MODE: + return self.async_create_entry( + title=CONF_CONNECTION_DEMO_MODE_LABEL, data=user_input + ) + return self.async_show_form( step_id="connection_selection", data_schema=CONNECTION_SCHEMA, @@ -167,8 +168,10 @@ async def _test_credentials_cloud_mygekko(self, username, apikey, gekkoid): client = MyGekkoQueryApiClient(username, apikey, gekkoid, session) await client.try_connect() return True + except ClientConnectorError: + _LOGGER.error("ClientConnectorError") except MyGekkoError: - pass + _LOGGER.error("MyGekkoError") return False async def _test_credentials_local_mygekko(self, ip_address, username, password): @@ -178,46 +181,9 @@ async def _test_credentials_local_mygekko(self, ip_address, username, password): client = MyGekkoLocalApiClient(username, password, session, ip_address) await client.try_connect() return True + except ClientConnectorError: + _LOGGER.error("ClientConnectorError") except MyGekkoError: - pass - return False - + _LOGGER.error("MyGekkoError") -class MyGekkoOptionsFlowHandler(config_entries.OptionsFlow): - """Config flow options handler for mygekko.""" - - def __init__(self, config_entry): - """Initialize HACS options flow.""" - self.config_entry = config_entry - self.options = dict(config_entry.options) - - async def async_step_init(self, user_input=None): # pylint: disable=unused-argument - """Manage the options.""" - return await self.async_step_user() - - async def async_step_user(self, user_input=None): - """Handle a flow initialized by the user.""" - if user_input is not None: - self.options.update(user_input) - return await self._update_options() - - return self.async_show_form( - step_id="user", - data_schema=vol.Schema( - { - vol.Required(x, default=self.options.get(x, True)): bool - for x in sorted(PLATFORMS) - }, - { - vol.Required( - CONF_DEMO_MODE, default=self.options.get(CONF_DEMO_MODE, False) - ): bool - }, - ), - ) - - async def _update_options(self): - """Update config entry options.""" - return self.async_create_entry( - title=self.config_entry.data.get(CONF_USERNAME), data=self.options - ) + return False diff --git a/custom_components/mygekko/const.py b/custom_components/mygekko/const.py index cf5cae8..4b202a1 100644 --- a/custom_components/mygekko/const.py +++ b/custom_components/mygekko/const.py @@ -31,6 +31,8 @@ CONF_CONNECTION_MY_GEKKO_CLOUD_LABEL = "MyGekko Plus Query API" CONF_CONNECTION_LOCAL = "local" CONF_CONNECTION_LOCAL_LABEL = "Local" +CONF_CONNECTION_DEMO_MODE = "demo_mode" +CONF_CONNECTION_DEMO_MODE_LABEL = "Demo Mode" # Defaults DEFAULT_NAME = DOMAIN diff --git a/custom_components/mygekko/manifest.json b/custom_components/mygekko/manifest.json index 93015fe..352afd6 100644 --- a/custom_components/mygekko/manifest.json +++ b/custom_components/mygekko/manifest.json @@ -8,6 +8,6 @@ "iot_class": "cloud_polling", "issue_tracker": "https://github.com/stephanu/mygekko/issues", "loggers": ["PyMyGekko"], - "requirements": ["PyMyGekko==1.1.0rc5"], + "requirements": ["PyMyGekko==1.1.0rc6"], "version": "1.1.0" } diff --git a/custom_components/mygekko/translations/de.json b/custom_components/mygekko/translations/de.json index d1a2007..fda8dc1 100644 --- a/custom_components/mygekko/translations/de.json +++ b/custom_components/mygekko/translations/de.json @@ -2,65 +2,49 @@ "config": { "step": { "connection_selection": { - "description": "Die Integration kann sich mit Ihrem MyGekko-Gerät lokal oder über die MyGekko Plus Query API verbinden.", + "description": "Die Integration kann sich mit deinem MyGekko-Gerät lokal oder über die MyGekko Plus Query API verbinden.", "data": { "connection_type": "Verbindungstyp" + }, + "data_description": { + "connection_type": "Im Demomodus werden statische Daten für alle unterstüzten Geräte geladen. Es wird keine Verbindung zu einem MyGekko hergestellt." } }, "connection_mygekko_cloud": { - "description": "Bitte geben Sie die folgenden Anmeldedaten ein, um eine Verbindung über die MyGekko Plus Query API herzustellen.", + "description": "Bitte gib die folgenden Anmeldedaten ein, um eine Verbindung über die MyGekko Plus Query API herzustellen.", "data": { "username": "Benutzername", "api_key": "Api Key", "gekkoid": "Gekko ID" }, "data_description": { - "username": "Ihr myGEKKO Plus Benutzername.", + "username": "Dein myGEKKO Plus Benutzername.", "api_key": "Der Key wird über 'Erweiterte Einstellungen' im Menü myGEKKO Plus generiert.", "gekkoid": "Ihr myGEKKO ID wird im Menü Systeminfo (Zahnrad > Systeminfo > myGEKKO ID) angezeigt." } }, "connection_local": { - "description": "Bitte geben Sie die folgenden Anmeldedaten ein, um eine lokale Verbindung zu Ihrem MyGekko herzustellen.", + "description": "Bitte gib die folgenden Anmeldedaten ein, um eine lokale Verbindung zu Ihrem MyGekko herzustellen.", "data": { "ip_address": "IP Adresse", "username": "Benutzername", "password": "Passwort" }, "data_description": { - "ip_address": "Die IP Adresse ihres MyGekko.", + "ip_address": "Die IP Adresse deines MyGekko.", "username": "Der Benutzername eines Benutzers der lokalen Query API.", "password": "Das Passwort des Benutzers." } } }, "error": { - "auth_cloud": "Benutzername, Api Key oder Gekko ID sind falsch.", - "auth_local": "Benutzername, Password oder IP Adresse sind falsch." + "auth_cloud": "Benutzername, Api Key oder Gekko ID sind falsch. Details findest du in den Protokollen.", + "auth_local": "Benutzername, Password oder IP Adresse sind falsch. Details findest du in den Protokollen." }, "abort": { "single_instance_allowed": "Es ist nur eine einzige Instanz zulässig." } }, - "options": { - "step": { - "user": { - "data": { - "binary_sensor": "Binärsensoren aktiviert", - "sensor": "Sensoren aktiviert", - "cover": "Abdeckungen aktiviert", - "light": "Lichter aktiviert", - "climate": "Klimaanlagen aktiviert", - "switch": "Schalter aktiviert", - "scene": "Szenen aktiviert", - "water_heater": "Warmwasserboiler aktiviert", - "button": "Schaltflächen aktiviert", - "demo_mode": "Demo Mode" - }, - "demo_mode": "Demo Mode" - } - } - }, "entity": { "climate": { "mygekko_roomtemp": { diff --git a/custom_components/mygekko/translations/en.json b/custom_components/mygekko/translations/en.json index 14822cb..6c72126 100644 --- a/custom_components/mygekko/translations/en.json +++ b/custom_components/mygekko/translations/en.json @@ -5,6 +5,9 @@ "description": "The integration can connect to your MyGekko device locally or via the MyGekko Plus Query API.", "data": { "connection_type": "Connection Type" + }, + "data_description": { + "connection_type": "In demo mode, static data is loaded for all supported devices. No connection to a MyGekko is established." } }, "connection_mygekko_cloud": { @@ -35,31 +38,13 @@ } }, "error": { - "auth_cloud": "Username/Api Key/Gekko ID is wrong.", - "auth_local": "Username/Password/IP address is wrong." + "auth_cloud": "Username/Api Key/Gekko ID is wrong. Please see the logs for details.", + "auth_local": "Username/Password/IP address is wrong. Please see the logs for details." }, "abort": { "single_instance_allowed": "Only a single instance is allowed." } }, - "options": { - "step": { - "user": { - "data": { - "binary_sensor": "Binary sensor enabled", - "sensor": "Sensor enabled", - "cover": "Cover enabled", - "light": "Light enabled", - "climate": "Climate enabled", - "switch": "Switch enabled", - "scene": "Scene enabled", - "water_heater": "Water Heater enabled", - "button": "Button enabled", - "demo_mode": "Demo Mode" - } - } - } - }, "entity": { "climate": { "mygekko_roomtemp": { diff --git a/custom_components/mygekko/translations/fr.json b/custom_components/mygekko/translations/fr.json index 7267203..52ceed7 100644 --- a/custom_components/mygekko/translations/fr.json +++ b/custom_components/mygekko/translations/fr.json @@ -5,6 +5,9 @@ "description": "L'intégration peut se connecter à votre appareil MyGekko localement ou via l'API MyGekko Plus Query.", "data": { "connection_type": "Type de connexion" + }, + "data_description": { + "connection_type": "En mode démo, des données statiques sont chargées pour tous les appareils pris en charge. Aucune connexion avec un MyGekko n'est établie." } }, "connection_mygekko_cloud": { @@ -35,27 +38,55 @@ } }, "error": { - "auth_cloud": "Nom d'utilisateur ou Clé Api ou ID Gekko erroné.", - "auth_local": "Nom d'utilisateur ou le mot de passe ou l'adresse IP erroné." + "auth_cloud": "Nom d'utilisateur ou Clé Api ou ID Gekko erroné. Veuillez consulter les journaux pour plus de détails.", + "auth_local": "Nom d'utilisateur ou le mot de passe ou l'adresse IP erroné. Veuillez consulter les journaux pour plus de détails." }, "abort": { "single_instance_allowed": "Une seule instance est autorisée." } }, - "options": { - "step": { - "user": { - "data": { - "binary_sensor": "Capteur binaire activé", - "sensor": "Capteur activé", - "cover": "Couverture activé", - "light": "Lumière activée", - "climate": "Climat activé", - "switch": "Interrupteur activé", - "scene": "Scène activée", - "water_heater": "Chauffe-eau activé", - "button": "Bouton activé", - "demo_mode": "Mode démo" + "entity": { + "climate": { + "mygekko_roomtemp": { + "state_attributes": { + "preset_mode": { + "state": { + "1": "Arrêt", + "8": "Confort", + "16": "Réduit", + "64": "Manuel", + "256": "Veille" + } + } + } + } + }, + "select": { + "mygekko_vent_bypass": { + "name": "By-pass", + "state": { + "0": "Auto", + "1": "Manuel", + "2": "L'été" + } + }, + "mygekko_vent_working_level": { + "name": "Niveau", + "state": { + "1": "Niveau 1", + "2": "Niveau 2", + "3": "Niveau 3", + "4": "Niveau 4", + "0": "Arrêt" + } + }, + "mygekko_vent_working_mode": { + "name": "Mode de fonctionnement", + "state": { + "0": "Auto", + "1": "Manuel", + "2": "Pluggit Auto", + "3": "Pluggit semaine" } } }, @@ -70,7 +101,7 @@ "name": "Énergie totale" }, "mygekko_energycost_energyToday": { - "name": "Total Energy Today" + "name": "Énergie totale aujourd'hui" }, "mygekko_energycost_energyMonth": { "name": "Énergie totale ce mois-ci" diff --git a/custom_components/mygekko/translations/it.json b/custom_components/mygekko/translations/it.json index 2add686..6af79d9 100644 --- a/custom_components/mygekko/translations/it.json +++ b/custom_components/mygekko/translations/it.json @@ -5,6 +5,9 @@ "description": "L'integrazione può connettersi al dispositivo MyGekko localmente o tramite l'API MyGekko Plus Query.", "data": { "connection_type": "Tipo di connessione" + }, + "data_description": { + "connection_type": "In modalità demo, vengono caricati dati statici per tutti i dispositivi supportati. Non viene stabilita alcuna connessione con un MyGekko." } }, "connection_mygekko_cloud": { @@ -35,31 +38,13 @@ } }, "error": { - "auth_cloud": "Il nome utente/chiave API/ID Gekko è sbagliato.", - "auth_local": "Nome utente/Password/Indirizzo IP errati." + "auth_cloud": "Il nome utente/chiave API/ID Gekko è sbagliato. Per i dettagli, consultare i registri.", + "auth_local": "Nome utente/Password/Indirizzo IP errati. Per i dettagli, consultare i registri." }, "abort": { "single_instance_allowed": "È consentita una sola istanza." } }, - "options": { - "step": { - "user": { - "data": { - "binary_sensor": "Sensore binario abilitato", - "sensor": "Sensore abilitato", - "cover": "Cala abilitato", - "light": "Luce abilitata", - "climate": "Clima abilitato", - "switch": "Interruttore abilitato", - "scene": "Scena abilitata", - "water_heater": "Scaldabagno abilitato", - "button": "Pulsante abilitato", - "demo_mode": "Modalità demo" - } - } - } - }, "entity": { "climate": { "mygekko_roomtemp": { diff --git a/custom_components/mygekko/translations/nb.json b/custom_components/mygekko/translations/nb.json index e04170d..85ed497 100644 --- a/custom_components/mygekko/translations/nb.json +++ b/custom_components/mygekko/translations/nb.json @@ -5,6 +5,9 @@ "description": "De integratie kan lokaal of via de MyGekko Plus Query API verbinding maken met je MyGekko-apparaat.", "data": { "connection_type": "Type aansluiting" + }, + "data_description": { + "connection_type": "In modalità demo, vengono caricati dati statici per tutti i dispositivi supportati. Non viene stabilita alcuna connessione con un MyGekko." } }, "connection_mygekko_cloud": { @@ -35,27 +38,55 @@ } }, "error": { - "auth": "Brukernavn/Api sleutel/Gekko ID er feil.", - "auth_local": "Brukernavn/Wachtwoord/IP-adres er feil." + "auth": "Brukernavn/Api sleutel/Gekko ID er feil. Raadpleeg de logboeken voor meer informatie.", + "auth_local": "Brukernavn/Wachtwoord/IP-adres er feil. Raadpleeg de logboeken voor meer informatie." }, "abort": { "single_instance_allowed": "Denne integrasjonen kan kun konfigureres en gang." } }, - "options": { - "step": { - "user": { - "data": { - "binary_sensor": "Binær sensor aktivert", - "sensor": "Sensor aktivert", - "cover": "Cover aktivert", - "light": "Licht aktivert", - "climate": "Klimaat aktivert", - "switch": "Bryter aktivert", - "scene": "Scène aktivert", - "water_heater": "Waterverwarming aktivert", - "button": "Bouton activé", - "demo_mode": "Demomodus" + "entity": { + "climate": { + "mygekko_roomtemp": { + "state_attributes": { + "preset_mode": { + "state": { + "1": "Uit", + "8": "Comfort", + "16": "Verminderd", + "64": "Handmatig", + "256": "Stand-by" + } + } + } + } + }, + "select": { + "mygekko_vent_bypass": { + "name": "Omleiding", + "state": { + "0": "Auto", + "1": "Handmatig", + "2": "Zomer" + } + }, + "mygekko_vent_working_level": { + "name": "Niveau", + "state": { + "1": "Niveau 1", + "2": "Niveau 2", + "3": "Niveau 3", + "4": "Niveau 4", + "0": "Uit" + } + }, + "mygekko_vent_working_mode": { + "name": "Bedrijfsmodus", + "state": { + "0": "Auto", + "1": "Handmatig", + "2": "Pluggit Auto", + "3": "Pluggit week" } } }, diff --git a/requirements_test.txt b/requirements_test.txt index 099114e..fd00bfb 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -1,4 +1,4 @@ -r requirements_dev.txt pytest-asyncio pytest-homeassistant-custom-component==0.13.82 -PyMyGekko==1.1.0rc5 +PyMyGekko==1.1.0rc6