Skip to content

Commit

Permalink
Fixed demo mode and translations. Fixed ssl connection error.
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanU committed Dec 10, 2023
1 parent 67f2243 commit 973b412
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 152 deletions.
7 changes: 6 additions & 1 deletion custom_components/mygekko/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
66 changes: 16 additions & 50 deletions custom_components/mygekko/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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,
}
)
}
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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):
Expand All @@ -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
2 changes: 2 additions & 0 deletions custom_components/mygekko/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion custom_components/mygekko/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
36 changes: 10 additions & 26 deletions custom_components/mygekko/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
25 changes: 5 additions & 20 deletions custom_components/mygekko/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down
65 changes: 48 additions & 17 deletions custom_components/mygekko/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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"
}
}
},
Expand All @@ -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"
Expand Down
Loading

0 comments on commit 973b412

Please sign in to comment.