2
2
from __future__ import annotations
3
3
4
4
import asyncio
5
+ from enum import Enum
5
6
import logging
6
7
7
8
from homeassistant .components .sensor import (
40
41
41
42
from .serial_reader import LinkyTICReader
42
43
43
- from enum import Enum
44
44
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
+
64
64
_LOGGER = logging .getLogger (__name__ )
65
65
66
66
@@ -468,7 +468,7 @@ async def async_setup_entry(
468
468
config_uniq_id = config_entry .entry_id ,
469
469
serial_reader = serial_reader ,
470
470
category = EntityCategory .DIAGNOSTIC ,
471
- ),
471
+ ),
472
472
RegularStrSensor (
473
473
tag = "PPOINTE" ,
474
474
name = "Profil du prochain jour de pointe" ,
@@ -486,7 +486,7 @@ async def async_setup_entry(
486
486
serial_reader = serial_reader ,
487
487
icon = "mdi:list-status" ,
488
488
category = EntityCategory .DIAGNOSTIC ,
489
- ),
489
+ ),
490
490
StatusRegisterData (
491
491
name = "Statut contact sec" ,
492
492
config_title = config_entry .title ,
@@ -1800,7 +1800,8 @@ def update(self):
1800
1800
self ._attr_available = True
1801
1801
# Save value
1802
1802
self ._last_value = value
1803
-
1803
+
1804
+
1804
1805
class DateEtHeureSensor (RegularStrSensor ):
1805
1806
"""Date et heure courante sensor."""
1806
1807
@@ -1820,10 +1821,10 @@ def __init__(
1820
1821
self ._last_value : str | None = None
1821
1822
self ._serial_controller = serial_reader
1822
1823
self ._tag = "DATE"
1823
-
1824
+
1824
1825
if category :
1825
1826
self ._attr_entity_category = category
1826
-
1827
+
1827
1828
# Generic Entity properties
1828
1829
self ._attr_unique_id = f"{ DOMAIN } _{ config_uniq_id } _{ self ._tag .lower ()} "
1829
1830
@@ -1866,14 +1867,14 @@ def update(self):
1866
1867
)
1867
1868
self ._attr_available = True
1868
1869
# 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)"
1875
1875
self ._last_value = horodate [5 :7 ] + "/" + horodate [3 :5 ] + "/" + horodate [1 :3 ] + " " + horodate [7 :9 ] + ":" + horodate [9 :11 ] + saison
1876
-
1876
+
1877
+
1877
1878
class ProfilDuProchainJourCalendrierFournisseurSensor (RegularStrSensor ):
1878
1879
"""Profil du prochain jour du calendrier fournisseur sensor."""
1879
1880
@@ -1893,10 +1894,10 @@ def __init__(
1893
1894
self ._last_value : str | None = None
1894
1895
self ._serial_controller = serial_reader
1895
1896
self ._tag = "PJOURF+1"
1896
-
1897
+
1897
1898
if category :
1898
1899
self ._attr_entity_category = category
1899
-
1900
+
1900
1901
# Generic Entity properties
1901
1902
self ._attr_unique_id = f"{ DOMAIN } _{ config_uniq_id } _{ self ._tag .lower ()} "
1902
1903
@@ -1939,8 +1940,9 @@ def update(self):
1939
1940
)
1940
1941
self ._attr_available = True
1941
1942
# Save value
1942
- self ._last_value = value .replace (" NONUTILE" , "" )
1943
-
1943
+ self ._last_value = value .replace (" NONUTILE" , "" )
1944
+
1945
+
1944
1946
class StatusRegisterData (RegularStrSensor ):
1945
1947
"""Data from status register."""
1946
1948
_attr_has_entity_name = True
@@ -1953,7 +1955,7 @@ def __init__(
1953
1955
config_uniq_id : str ,
1954
1956
serial_reader : LinkyTICReader ,
1955
1957
data : StatusRegisterData ,
1956
- enabled_by_default : bool = True ,
1958
+ enabled_by_default : bool = True ,
1957
1959
icon : str | None = None ,
1958
1960
category : EntityCategory | None = None ,
1959
1961
) -> None :
@@ -1975,13 +1977,13 @@ def __init__(
1975
1977
self ._config_title ,
1976
1978
self ._attr_unique_id ,
1977
1979
)
1978
-
1980
+
1979
1981
if icon :
1980
1982
self ._attr_icon = icon
1981
1983
if category :
1982
1984
self ._attr_entity_category = category
1983
1985
self ._attr_entity_registry_enabled_default = enabled_by_default
1984
-
1986
+
1985
1987
if category :
1986
1988
self ._attr_entity_category = category
1987
1989
@@ -2023,136 +2025,135 @@ def update(self):
2023
2025
self ._tag ,
2024
2026
)
2025
2027
self ._attr_available = True
2026
-
2028
+
2027
2029
try :
2028
2030
val = int (value , 16 )
2029
2031
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 :
2083
2085
self ._last_value = "Désactivée"
2084
- elif etat == 1 :
2086
+ elif etat == 1 :
2085
2087
self ._last_value = "Activée sans sécurité"
2086
- elif etat == 3 :
2088
+ elif etat == 3 :
2087
2089
self ._last_value = "Activée avec sécurité"
2088
2090
else :
2089
2091
self ._last_value = "Inconnue"
2090
2092
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 :
2094
2096
self ._last_value = "New/Unlock"
2095
- elif etat == 1 :
2097
+ elif etat == 1 :
2096
2098
self ._last_value = "New/Lock"
2097
- elif etat == 2 :
2099
+ elif etat == 2 :
2098
2100
self ._last_value = "Registered"
2099
2101
else :
2100
2102
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é"
2104
2103
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 :
2108
2110
self ._last_value = "Pas d'annonce"
2109
- elif etat == 1 :
2111
+ elif etat == 1 :
2110
2112
self ._last_value = "Bleu"
2111
- elif etat == 2 :
2113
+ elif etat == 2 :
2112
2114
self ._last_value = "Blanc"
2113
2115
else :
2114
2116
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 :
2119
2121
self ._last_value = "Pas d'annonce"
2120
- elif etat == 1 :
2122
+ elif etat == 1 :
2121
2123
self ._last_value = "Bleu"
2122
- elif etat == 2 :
2124
+ elif etat == 2 :
2123
2125
self ._last_value = "Blanc"
2124
2126
else :
2125
2127
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 :
2130
2132
self ._last_value = "Pas de préavis en cours"
2131
- elif etat == 1 :
2133
+ elif etat == 1 :
2132
2134
self ._last_value = "Préavis PM1 en cours"
2133
- elif etat == 2 :
2135
+ elif etat == 2 :
2134
2136
self ._last_value = "Préavis PM2 en cours"
2135
2137
else :
2136
2138
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 :
2141
2143
self ._last_value = "Pas de pointe mobile"
2142
- elif etat == 1 :
2144
+ elif etat == 1 :
2143
2145
self ._last_value = "PM1 en cours"
2144
- elif etat == 2 :
2146
+ elif etat == 2 :
2145
2147
self ._last_value = "PM2 en cours"
2146
2148
else :
2147
2149
self ._last_value = "PM3 en cours"
2148
-
2150
+
2149
2151
else :
2150
2152
self ._last_value = self ._data .name
2151
-
2153
+
2152
2154
except ValueError :
2153
2155
_LOGGER .error (
2154
2156
"%s: Invalid status register : %s" ,
2155
- self ._config_title ,
2156
- value ,
2157
+ self ._config_title ,
2158
+ value ,
2157
2159
)
2158
-
0 commit comments