-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update setup and ConfigEntry #1
Changes from all commits
7cf9e7e
dcff022
3f58a7a
c0cb939
1aac339
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
"""Config flow for linkytic integration.""" | ||
|
||
from __future__ import annotations | ||
|
||
# import dataclasses | ||
|
@@ -13,6 +14,7 @@ | |
from homeassistant.core import callback | ||
from homeassistant.data_entry_flow import FlowResult | ||
from homeassistant.helpers import selector | ||
from homeassistant.components import usb | ||
|
||
from .const import ( | ||
DOMAIN, | ||
|
@@ -39,12 +41,8 @@ | |
vol.Required(SETUP_TICMODE, default=TICMODE_HISTORIC): selector.SelectSelector( | ||
selector.SelectSelectorConfig( | ||
options=[ | ||
selector.SelectOptionDict( | ||
value=TICMODE_HISTORIC, label=TICMODE_HISTORIC_LABEL | ||
), | ||
selector.SelectOptionDict( | ||
value=TICMODE_STANDARD, label=TICMODE_STANDARD_LABEL | ||
), | ||
selector.SelectOptionDict(value=TICMODE_HISTORIC, label=TICMODE_HISTORIC_LABEL), | ||
selector.SelectOptionDict(value=TICMODE_STANDARD, label=TICMODE_STANDARD_LABEL), | ||
] | ||
), | ||
), | ||
|
@@ -58,43 +56,41 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): | |
"""Handle a config flow for linkytic.""" | ||
|
||
VERSION = 1 | ||
MINOR_VERSION = 2 | ||
|
||
async def async_step_user( | ||
self, user_input: dict[str, Any] | None = None | ||
) -> FlowResult: | ||
async def async_step_user(self, user_input: dict[str, Any] | None = None) -> FlowResult: | ||
"""Handle the initial step.""" | ||
# No input | ||
if user_input is None: | ||
return self.async_show_form( | ||
step_id="user", data_schema=STEP_USER_DATA_SCHEMA | ||
) | ||
return self.async_show_form(step_id="user", data_schema=STEP_USER_DATA_SCHEMA) | ||
# Validate input | ||
await self.async_set_unique_id(DOMAIN + "_" + user_input[SETUP_SERIAL]) | ||
await self.async_set_unique_id(DOMAIN + "_" + user_input[SETUP_SERIAL]) # TODO: switch to meter s/n | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ici le unique id concerne la config et non le device : cette configuration target bien sur le device (USB) et non sur le linky derrière. Je garderais Gardons l'actuel et enlevons ce TODO, cela évitera de mauvaises surprises à l'avenir. |
||
self._abort_if_unique_id_configured() | ||
|
||
# Search for serial/by-id, which SHOULD be a persistent name to serial interface. | ||
_port = await self.hass.async_add_executor_job(usb.get_serial_by_id, user_input[SETUP_SERIAL]) | ||
|
||
errors = {} | ||
title = user_input[SETUP_SERIAL] | ||
try: | ||
linky_tic_tester( | ||
device=user_input[SETUP_SERIAL], | ||
device=_port, | ||
std_mode=user_input[SETUP_TICMODE] == TICMODE_STANDARD, | ||
) | ||
except CannotConnect as cannot_connect: | ||
_LOGGER.error("%s: can not connect: %s", title, cannot_connect) | ||
errors["base"] = "cannot_connect" | ||
except CannotRead as cannot_read: | ||
_LOGGER.error( | ||
"%s: can not read a line after connection: %s", title, cannot_read | ||
) | ||
_LOGGER.error("%s: can not read a line after connection: %s", title, cannot_read) | ||
errors["base"] = "cannot_read" | ||
except Exception as exc: # pylint: disable=broad-except | ||
_LOGGER.exception("Unexpected exception: %s", exc) | ||
errors["base"] = "unknown" | ||
else: | ||
user_input[SETUP_SERIAL] = _port | ||
return self.async_create_entry(title=title, data=user_input) | ||
|
||
return self.async_show_form( | ||
step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors | ||
) | ||
return self.async_show_form(step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors) | ||
|
||
# async def async_step_usb(self, discovery_info: UsbServiceInfo) -> FlowResult: | ||
# """Handle a flow initialized by USB discovery.""" | ||
|
@@ -116,9 +112,7 @@ def __init__(self, config_entry: config_entries.ConfigEntry) -> None: | |
"""Initialize options flow.""" | ||
self.config_entry = config_entry | ||
|
||
async def async_step_init( | ||
self, user_input: dict[str, Any] | None = None | ||
) -> FlowResult: | ||
async def async_step_init(self, user_input: dict[str, Any] | None = None) -> FlowResult: | ||
"""Manage the options.""" | ||
if user_input is not None: | ||
return self.async_create_entry(title="", data=user_input) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
"""Constants for the linkytic integration.""" | ||
|
||
import serial | ||
from termios import error | ||
from serial import SerialException, SEVENBITS, PARITY_EVEN, STOPBITS_ONE | ||
|
||
DOMAIN = "linkytic" | ||
|
||
# Some termios exceptions are uncaught by pyserial | ||
LINKY_IO_ERRORS = (SerialException, error) | ||
|
||
# Config Flow | ||
|
||
|
@@ -25,9 +28,9 @@ | |
# Protocol configuration | ||
# # https://www.enedis.fr/media/2035/download | ||
|
||
BYTESIZE = serial.SEVENBITS | ||
PARITY = serial.PARITY_EVEN | ||
STOPBITS = serial.STOPBITS_ONE | ||
BYTESIZE = SEVENBITS | ||
PARITY = PARITY_EVEN | ||
STOPBITS = STOPBITS_ONE | ||
|
||
MODE_STANDARD_BAUD_RATE = 9600 | ||
MODE_STANDARD_FIELD_SEPARATOR = b"\x09" | ||
|
@@ -36,7 +39,7 @@ | |
MODE_HISTORIC_FIELD_SEPARATOR = b"\x20" | ||
|
||
LINE_END = b"\r\n" | ||
FRAME_END = b"\r\x03\x02\n" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. La je veux en savoir plus :) |
||
FRAME_END = b"\x03\x02" | ||
|
||
SHORT_FRAME_DETECTION_TAGS = ["ADIR1", "ADIR2", "ADIR3"] | ||
SHORT_FRAME_FORCED_UPDATE_TAGS = [ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pourquoi ne pas faire de la fonction
read_serial_number()
une méthode de l'objetserial_reader
?Vous pouvez d'ailleurs passer le timeout à 9, Home Assistant ne commence à afficher des warning d'initialisation qu'à partir de 10s.