Skip to content

Commit

Permalink
Older api support (#53)
Browse files Browse the repository at this point in the history
Add support for older Protexiom/Protexial centrale.
Tested on a 2008 Protexiom
  • Loading branch information
the8tre authored Mar 27, 2024
1 parent c83c276 commit b5e7e30
Show file tree
Hide file tree
Showing 7 changed files with 363 additions and 74 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ Interval de rafraîchissement: de 15 secondes à 1 heure, 20 secondes par défau
### Compatibilité de version

Il est tout à fait possible que cette intégration soit compatible avec d'autres version de centrale Somfy telle que Protexiom. N'hésitez pas à m'en faire part si c'est le cas !
| Modèle | Version | Statut |
| -------------- | -------- | ------------------ |
| Protexial | `v8_1` | :white_check_mark: |
| Protexiom 5000 | `v10_3` | :white_check_mark: |
| Protexiom | `v?*?` | :grey_question: |
| Modèle | Version | Année | Statut |
| -------------- | ------- | ------ | ------------------ |
| Protexial | `v8_1` | `2010` | :white_check_mark: |
| Protexiom 5000 | `v10_3` | `2013` | :white_check_mark: |
| Protexiom | `v?_?` | `2008` | :white_check_mark: |
| Protexiom | `v?*?` | | :grey_question: |

Pour connaître la version de votre centrale: http://192.168.1.234/cfg/vers

Expand Down
39 changes: 38 additions & 1 deletion custom_components/somfy_protexial/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@
from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed

from .const import API, CONF_CODES, COORDINATOR, DEVICE_INFO, DOMAIN
from .const import (
API,
CONF_API_TYPE,
CONF_CODES,
COORDINATOR,
DEVICE_INFO,
DOMAIN,
ApiType,
)
from .protexial import SomfyProtexial

_LOGGER = logging.getLogger(__name__)
Expand All @@ -45,13 +53,21 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.data.setdefault(DOMAIN, {})

session = aiohttp_client.async_create_clientsession(hass)
_LOGGER.debug(f"CONF_URL:{entry.data.get(CONF_URL)}")
_LOGGER.debug(f"CONF_API_TYPE:{entry.data.get(CONF_API_TYPE)}")
_LOGGER.debug(f"CONF_USERNAME:{entry.data.get(CONF_USERNAME)}")
_LOGGER.debug(f"CONF_PASSWORD:{entry.data.get(CONF_PASSWORD)}")
_LOGGER.debug(f"CONF_CODES:{entry.data.get(CONF_CODES)}")

protexial = SomfyProtexial(
session=session,
url=entry.data.get(CONF_URL),
api_type=entry.data.get(CONF_API_TYPE),
username=entry.data.get(CONF_USERNAME),
password=entry.data.get(CONF_PASSWORD),
codes=entry.data.get(CONF_CODES),
)

await protexial.init()

async def _get_status():
Expand Down Expand Up @@ -119,6 +135,27 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return unload_ok


async def async_migrate_entry(hass, config_entry: ConfigEntry):
"""Migrate old entry."""
_LOGGER.debug("Migrating from version %s", config_entry.version)

if config_entry.version == 1:
if config_entry.minor_version < 2:
# In config version 1.1 only Protexial ApiType was supported
# We can safely force the API to ApiType.PROTEXIAL
new = {**config_entry.data}
new[CONF_API_TYPE] = ApiType.PROTEXIAL
hass.config_entries.async_update_entry(
config_entry, data=new, minor_version=2, version=1
)
_LOGGER.debug(
"Migration to version %s.%s successful",
config_entry.version,
config_entry.minor_version,
)
return True


async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle an options update."""
await hass.config_entries.async_reload(entry.entry_id)
12 changes: 11 additions & 1 deletion custom_components/somfy_protexial/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,22 @@
)
import voluptuous as vol

from .const import CONF_ARM_CODE, CONF_CODE, CONF_CODES, CONF_MODES, DOMAIN
from .const import (
CONF_API_TYPE,
CONF_ARM_CODE,
CONF_CODE,
CONF_CODES,
CONF_MODES,
DOMAIN,
)
from .protexial import SomfyProtexial

_LOGGER = logging.getLogger(__name__)


class ProtexialConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
VERSION = 1
MINOR_VERSION = 2

async def async_step_user(self, user_input):
if self._async_current_entries():
Expand All @@ -47,6 +55,7 @@ async def async_step_user(self, user_input):
session = aiohttp_client.async_create_clientsession(self.hass)
self.protexial = SomfyProtexial(session, self.url)
try:
self.api_type = await self.protexial.guess_and_set_api_type()
challenge = await self.protexial.get_challenge()
return await self.async_step_login(None, challenge)
except Exception as e:
Expand Down Expand Up @@ -113,6 +122,7 @@ async def async_step_config(self, user_input):
title=self.url,
data={
CONF_URL: self.url,
CONF_API_TYPE: self.api_type,
CONF_USERNAME: self.username,
CONF_PASSWORD: self.password,
CONF_CODES: self.codes,
Expand Down
21 changes: 21 additions & 0 deletions custom_components/somfy_protexial/const.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from enum import Enum

from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from homeassistant.const import EntityCategory

DOMAIN = "somfy_protexial"

CONF_API_TYPE = "api_type"
CONF_CODE = "code"
CONF_CODES = "codes"
CONF_MODES = "modes"
Expand All @@ -12,6 +15,24 @@
COORDINATOR = "coordinator"
DEVICE_INFO = "device_info"


class ApiType(str, Enum):
PROTEXIAL = "protexial"
PROTEXIOM = "protexiom"


class Page(str, Enum):
LOGIN = "login"
LOGOUT = "logout"
PILOTAGE = "pilotage"
STATUS = "status"
ERROR = "error"
ELEMENTS = "elements"
PRINT = "print"
VERSION = "version"
DEFAULT = "default"


BINARY_SENSORS = [
{
"id": "battery",
Expand Down
3 changes: 2 additions & 1 deletion custom_components/somfy_protexial/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"documentation": "https://github.com/the8tre/somfy-protexial",
"iot_class": "local_polling",
"issue_tracker": "https://github.com/the8tre/somfy-protexial/issues",
"loggers": ["custom_components.somfy_protexial"],
"requirements": ["pyquery==2.0.0"],
"version": "1.0.6"
"version": "1.1.0"
}
Loading

0 comments on commit b5e7e30

Please sign in to comment.