Skip to content

Commit 271a09e

Browse files
committed
linting
1 parent 1a7dd60 commit 271a09e

File tree

1 file changed

+132
-131
lines changed

1 file changed

+132
-131
lines changed

custom_components/linkytic/sensor.py

+132-131
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from __future__ import annotations
33

44
import asyncio
5+
from enum import Enum
56
import logging
67

78
from homeassistant.components.sensor import (
@@ -40,27 +41,26 @@
4041

4142
from .serial_reader import LinkyTICReader
4243

43-
from enum import Enum
4444
class StatusRegister(Enum):
45-
CONTACT_SEC=1,
46-
ORGANE_DE_COUPURE=2,
47-
ETAT_DU_CACHE_BORNE_DISTRIBUTEUR=3,
48-
SURTENSION_SUR_UNE_DES_PHASES=4,
49-
DEPASSEMENT_PUISSANCE_REFERENCE=5,
50-
PRODUCTEUR_CONSOMMATEUR=6,
51-
SENS_ENERGIE_ACTIVE=7,
52-
TARIF_CONTRAT_FOURNITURE=8,
53-
TARIF_CONTRAT_DISTRIBUTEUR=9,
54-
MODE_DEGRADE_HORLOGE=10,
55-
MODE_TIC=11,
56-
ETAT_SORTIE_COMMUNICATION_EURIDIS=12,
57-
STATUS_CPL=13,
58-
SYNCHRO_CPL=14,
59-
COULEUR_JOUR_CONTRAT_TEMPO=15,
60-
COULEUR_LENDEMAIN_CONTRAT_TEMPO=16,
61-
PREAVIS_POINTES_MOBILES=17,
62-
POINTE_MOBILE=18
63-
45+
CONTACT_SEC = 1,
46+
ORGANE_DE_COUPURE = 2,
47+
ETAT_DU_CACHE_BORNE_DISTRIBUTEUR = 3,
48+
SURTENSION_SUR_UNE_DES_PHASES = 4,
49+
DEPASSEMENT_PUISSANCE_REFERENCE = 5,
50+
PRODUCTEUR_CONSOMMATEUR = 6,
51+
SENS_ENERGIE_ACTIVE = 7,
52+
TARIF_CONTRAT_FOURNITURE = 8,
53+
TARIF_CONTRAT_DISTRIBUTEUR = 9,
54+
MODE_DEGRADE_HORLOGE = 10,
55+
MODE_TIC = 11,
56+
ETAT_SORTIE_COMMUNICATION_EURIDIS = 12,
57+
STATUS_CPL = 13,
58+
SYNCHRO_CPL = 14,
59+
COULEUR_JOUR_CONTRAT_TEMPO = 15,
60+
COULEUR_LENDEMAIN_CONTRAT_TEMPO = 16,
61+
PREAVIS_POINTES_MOBILES = 17,
62+
POINTE_MOBILE = 18
63+
6464
_LOGGER = logging.getLogger(__name__)
6565

6666

@@ -468,7 +468,7 @@ async def async_setup_entry(
468468
config_uniq_id=config_entry.entry_id,
469469
serial_reader=serial_reader,
470470
category=EntityCategory.DIAGNOSTIC,
471-
),
471+
),
472472
RegularStrSensor(
473473
tag="PPOINTE",
474474
name="Profil du prochain jour de pointe",
@@ -486,7 +486,7 @@ async def async_setup_entry(
486486
serial_reader=serial_reader,
487487
icon="mdi:list-status",
488488
category=EntityCategory.DIAGNOSTIC,
489-
),
489+
),
490490
StatusRegisterData(
491491
name="Statut contact sec",
492492
config_title=config_entry.title,
@@ -1800,7 +1800,8 @@ def update(self):
18001800
self._attr_available = True
18011801
# Save value
18021802
self._last_value = value
1803-
1803+
1804+
18041805
class DateEtHeureSensor(RegularStrSensor):
18051806
"""Date et heure courante sensor."""
18061807

@@ -1820,10 +1821,10 @@ def __init__(
18201821
self._last_value: str | None = None
18211822
self._serial_controller = serial_reader
18221823
self._tag = "DATE"
1823-
1824+
18241825
if category:
18251826
self._attr_entity_category = category
1826-
1827+
18271828
# Generic Entity properties
18281829
self._attr_unique_id = f"{DOMAIN}_{config_uniq_id}_{self._tag.lower()}"
18291830

@@ -1866,14 +1867,14 @@ def update(self):
18661867
)
18671868
self._attr_available = True
18681869
# Save value
1869-
saison="";
1870-
if horodate[0:1]=='E':
1871-
saison=" (Eté)"
1872-
elif horodate[0:1]=='H':
1873-
saison=" (Hiver)"
1874-
1870+
saison = ""
1871+
if horodate[0:1] == 'E':
1872+
saison = " (Eté)"
1873+
elif horodate[0:1] == 'H':
1874+
saison = " (Hiver)"
18751875
self._last_value = horodate[5:7] + "/" + horodate[3:5] + "/" + horodate[1:3] + " " + horodate[7:9] + ":" + horodate[9:11] + saison
1876-
1876+
1877+
18771878
class ProfilDuProchainJourCalendrierFournisseurSensor(RegularStrSensor):
18781879
"""Profil du prochain jour du calendrier fournisseur sensor."""
18791880

@@ -1893,10 +1894,10 @@ def __init__(
18931894
self._last_value: str | None = None
18941895
self._serial_controller = serial_reader
18951896
self._tag = "PJOURF+1"
1896-
1897+
18971898
if category:
18981899
self._attr_entity_category = category
1899-
1900+
19001901
# Generic Entity properties
19011902
self._attr_unique_id = f"{DOMAIN}_{config_uniq_id}_{self._tag.lower()}"
19021903

@@ -1939,8 +1940,9 @@ def update(self):
19391940
)
19401941
self._attr_available = True
19411942
# Save value
1942-
self._last_value=value.replace(" NONUTILE", "")
1943-
1943+
self._last_value = value.replace(" NONUTILE", "")
1944+
1945+
19441946
class StatusRegisterData(RegularStrSensor):
19451947
"""Data from status register."""
19461948
_attr_has_entity_name = True
@@ -1953,7 +1955,7 @@ def __init__(
19531955
config_uniq_id: str,
19541956
serial_reader: LinkyTICReader,
19551957
data: StatusRegisterData,
1956-
enabled_by_default: bool = True,
1958+
enabled_by_default: bool = True,
19571959
icon: str | None = None,
19581960
category: EntityCategory | None = None,
19591961
) -> None:
@@ -1975,13 +1977,13 @@ def __init__(
19751977
self._config_title,
19761978
self._attr_unique_id,
19771979
)
1978-
1980+
19791981
if icon:
19801982
self._attr_icon = icon
19811983
if category:
19821984
self._attr_entity_category = category
19831985
self._attr_entity_registry_enabled_default = enabled_by_default
1984-
1986+
19851987
if category:
19861988
self._attr_entity_category = category
19871989

@@ -2023,136 +2025,135 @@ def update(self):
20232025
self._tag,
20242026
)
20252027
self._attr_available = True
2026-
2028+
20272029
try:
20282030
val = int(value, 16)
20292031

2030-
# Save value
2031-
if self._data==StatusRegister.CONTACT_SEC:
2032-
self._last_value = "Ouvert" if (val&0x01) else "Fermé"
2033-
2034-
elif self._data==StatusRegister.ORGANE_DE_COUPURE:
2035-
val_organe_de_coupure=(val>>1)&0x07
2036-
if val_organe_de_coupure==0:
2037-
self._last_value="Fermé"
2038-
elif val_organe_de_coupure==1:
2039-
self._last_value="Ouvert sur surpuissance"
2040-
elif val_organe_de_coupure==2:
2041-
self._last_value="Ouvert sur surtension"
2042-
elif val_organe_de_coupure==3:
2043-
self._last_value="Ouvert sur délestage"
2044-
elif val_organe_de_coupure==4:
2045-
self._last_value="Ouvert sur ordre CPL ou Euridis"
2046-
elif val_organe_de_coupure==5:
2047-
self._last_value="Ouvert sur une surchauffe (>Imax)"
2048-
elif val_organe_de_coupure==6:
2049-
self._last_value="Ouvert sur une surchauffe (<Imax)"
2050-
2051-
elif self._data==StatusRegister.ETAT_DU_CACHE_BORNE_DISTRIBUTEUR:
2052-
self._last_value = "Ouvert" if ((val>>4)&0x01) else "Fermé"
2053-
2054-
elif self._data==StatusRegister.SURTENSION_SUR_UNE_DES_PHASES:
2055-
self._last_value = "Surtension" if ((val>>6)&0x01) else "Pas de surtension"
2056-
2057-
elif self._data==StatusRegister.DEPASSEMENT_PUISSANCE_REFERENCE:
2058-
self._last_value = "Dépassement en cours" if ((val>>7)&0x01) else "Pas de dépassement"
2059-
2060-
elif self._data==StatusRegister.PRODUCTEUR_CONSOMMATEUR:
2061-
self._last_value = "Producteur" if ((val>>8)&0x01) else "Consommateur"
2062-
2063-
elif self._data==StatusRegister.SENS_ENERGIE_ACTIVE:
2064-
self._last_value = "Energie active négative" if ((val>>9)&0x01) else "Energie active positive"
2065-
2066-
elif self._data==StatusRegister.TARIF_CONTRAT_FOURNITURE:
2067-
index=(val>>10)&0x0F
2068-
self._last_value = "Energie ventillée sur index " + str(index+1)
2069-
2070-
elif self._data==StatusRegister.TARIF_CONTRAT_DISTRIBUTEUR:
2071-
index=(val>>14)&0x03
2072-
self._last_value = "Energie ventillée sur index " + str(index+1)
2073-
2074-
elif self._data==StatusRegister.MODE_DEGRADE_HORLOGE:
2075-
self._last_value = "Horloge en mode dégradée" if ((val>>16)&0x01) else "Horloge correcte"
2076-
2077-
elif self._data==StatusRegister.MODE_TIC:
2078-
self._last_value = "Mode standard" if ((val>>17)&0x01) else "Mode historique"
2079-
2080-
elif self._data==StatusRegister.ETAT_SORTIE_COMMUNICATION_EURIDIS:
2081-
etat=(val>>19)&0x03
2082-
if etat==0:
2032+
# Save value
2033+
if self._data == StatusRegister.CONTACT_SEC:
2034+
self._last_value = "Ouvert" if (val & 0x01) else "Fermé"
2035+
2036+
elif self._data == StatusRegister.ORGANE_DE_COUPURE:
2037+
val_organe_de_coupure = (val >> 1) & 0x07
2038+
if val_organe_de_coupure == 0:
2039+
self._last_value = "Fermé"
2040+
elif val_organe_de_coupure == 1:
2041+
self._last_value = "Ouvert sur surpuissance"
2042+
elif val_organe_de_coupure == 2:
2043+
self._last_value = "Ouvert sur surtension"
2044+
elif val_organe_de_coupure == 3:
2045+
self._last_value = "Ouvert sur délestage"
2046+
elif val_organe_de_coupure == 4:
2047+
self._last_value = "Ouvert sur ordre CPL ou Euridis"
2048+
elif val_organe_de_coupure == 5:
2049+
self._last_value = "Ouvert sur une surchauffe (>Imax)"
2050+
elif val_organe_de_coupure == 6:
2051+
self._last_value = "Ouvert sur une surchauffe (<Imax)"
2052+
2053+
elif self._data == StatusRegister.ETAT_DU_CACHE_BORNE_DISTRIBUTEUR:
2054+
self._last_value = "Ouvert" if ((val >> 4) & 0x01) else "Fermé"
2055+
2056+
elif self._data == StatusRegister.SURTENSION_SUR_UNE_DES_PHASES:
2057+
self._last_value = "Surtension" if ((val >> 6) & 0x01) else "Pas de surtension"
2058+
2059+
elif self._data == StatusRegister.DEPASSEMENT_PUISSANCE_REFERENCE:
2060+
self._last_value = "Dépassement en cours" if ((val >> 7) & 0x01) else "Pas de dépassement"
2061+
2062+
elif self._data == StatusRegister.PRODUCTEUR_CONSOMMATEUR:
2063+
self._last_value = "Producteur" if ((val >> 8) & 0x01) else "Consommateur"
2064+
2065+
elif self._data == StatusRegister.SENS_ENERGIE_ACTIVE:
2066+
self._last_value = "Energie active négative" if ((val >> 9) & 0x01) else "Energie active positive"
2067+
2068+
elif self._data == StatusRegister.TARIF_CONTRAT_FOURNITURE:
2069+
index = (val >> 10) & 0x0F
2070+
self._last_value = "Energie ventillée sur index " + str(index + 1)
2071+
2072+
elif self._data == StatusRegister.TARIF_CONTRAT_DISTRIBUTEUR:
2073+
index = (val >> 14) & 0x03
2074+
self._last_value = "Energie ventillée sur index " + str(index + 1)
2075+
2076+
elif self._data == StatusRegister.MODE_DEGRADE_HORLOGE:
2077+
self._last_value = "Horloge en mode dégradée" if ((val >> 16) & 0x01) else "Horloge correcte"
2078+
2079+
elif self._data == StatusRegister.MODE_TIC:
2080+
self._last_value = "Mode standard" if ((val >> 17) & 0x01) else "Mode historique"
2081+
2082+
elif self._data == StatusRegister.ETAT_SORTIE_COMMUNICATION_EURIDIS:
2083+
etat = (val >> 19) & 0x03
2084+
if etat == 0:
20832085
self._last_value = "Désactivée"
2084-
elif etat==1:
2086+
elif etat == 1:
20852087
self._last_value = "Activée sans sécurité"
2086-
elif etat==3:
2088+
elif etat == 3:
20872089
self._last_value = "Activée avec sécurité"
20882090
else:
20892091
self._last_value = "Inconnue"
20902092

2091-
elif self._data==StatusRegister.STATUS_CPL:
2092-
etat=(val>>21)&0x03
2093-
if etat==0:
2093+
elif self._data == StatusRegister.STATUS_CPL:
2094+
etat = (val >> 21) & 0x03
2095+
if etat == 0:
20942096
self._last_value = "New/Unlock"
2095-
elif etat==1:
2097+
elif etat == 1:
20962098
self._last_value = "New/Lock"
2097-
elif etat==2:
2099+
elif etat == 2:
20982100
self._last_value = "Registered"
20992101
else:
21002102
self._last_value = "Inconnue"
2101-
2102-
elif self._data==StatusRegister.SYNCHRO_CPL:
2103-
self._last_value = "Compteur synchronisé" if ((val>>23)&0x01) else "Compteur non synchronisé"
21042103

2105-
elif self._data==StatusRegister.COULEUR_JOUR_CONTRAT_TEMPO:
2106-
etat=(val>>24)&0x03
2107-
if etat==0:
2104+
elif self._data == StatusRegister.SYNCHRO_CPL:
2105+
self._last_value = "Compteur synchronisé" if ((val >> 23) & 0x01) else "Compteur non synchronisé"
2106+
2107+
elif self._data == StatusRegister.COULEUR_JOUR_CONTRAT_TEMPO:
2108+
etat = (val >> 24) & 0x03
2109+
if etat == 0:
21082110
self._last_value = "Pas d'annonce"
2109-
elif etat==1:
2111+
elif etat == 1:
21102112
self._last_value = "Bleu"
2111-
elif etat==2:
2113+
elif etat == 2:
21122114
self._last_value = "Blanc"
21132115
else:
21142116
self._last_value = "Rouge"
2115-
2116-
elif self._data==StatusRegister.COULEUR_LENDEMAIN_CONTRAT_TEMPO:
2117-
etat=(val>>26)&0x03
2118-
if etat==0:
2117+
2118+
elif self._data == StatusRegister.COULEUR_LENDEMAIN_CONTRAT_TEMPO:
2119+
etat = (val >> 26) & 0x03
2120+
if etat == 0:
21192121
self._last_value = "Pas d'annonce"
2120-
elif etat==1:
2122+
elif etat == 1:
21212123
self._last_value = "Bleu"
2122-
elif etat==2:
2124+
elif etat == 2:
21232125
self._last_value = "Blanc"
21242126
else:
21252127
self._last_value = "Rouge"
2126-
2127-
elif self._data==StatusRegister.PREAVIS_POINTES_MOBILES:
2128-
etat=(val>>28)&0x03
2129-
if etat==0:
2128+
2129+
elif self._data == StatusRegister.PREAVIS_POINTES_MOBILES:
2130+
etat = (val >> 28) & 0x03
2131+
if etat == 0:
21302132
self._last_value = "Pas de préavis en cours"
2131-
elif etat==1:
2133+
elif etat == 1:
21322134
self._last_value = "Préavis PM1 en cours"
2133-
elif etat==2:
2135+
elif etat == 2:
21342136
self._last_value = "Préavis PM2 en cours"
21352137
else:
21362138
self._last_value = "Préavis PM3 en cours"
2137-
2138-
elif self._data==StatusRegister.POINTE_MOBILE:
2139-
etat=(val>>28)&0x03
2140-
if etat==0:
2139+
2140+
elif self._data == StatusRegister.POINTE_MOBILE:
2141+
etat = (val >> 28) & 0x03
2142+
if etat == 0:
21412143
self._last_value = "Pas de pointe mobile"
2142-
elif etat==1:
2144+
elif etat == 1:
21432145
self._last_value = "PM1 en cours"
2144-
elif etat==2:
2146+
elif etat == 2:
21452147
self._last_value = "PM2 en cours"
21462148
else:
21472149
self._last_value = "PM3 en cours"
2148-
2150+
21492151
else:
21502152
self._last_value = self._data.name
2151-
2153+
21522154
except ValueError:
21532155
_LOGGER.error(
21542156
"%s: Invalid status register : %s",
2155-
self._config_title,
2156-
value,
2157+
self._config_title,
2158+
value,
21572159
)
2158-

0 commit comments

Comments
 (0)