From fb29dce02caa82e04f5d24cc2a5a6c7d8688a524 Mon Sep 17 00:00:00 2001 From: Gianluca Sullazzo Date: Wed, 25 Sep 2024 15:11:17 +0200 Subject: [PATCH 1/2] add logic for PZO NORD --- custom_components/pun_sensor/__init__.py | 15 +++++++++++++-- custom_components/pun_sensor/const.py | 1 + custom_components/pun_sensor/sensor.py | 4 ++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/custom_components/pun_sensor/__init__.py b/custom_components/pun_sensor/__init__.py index ef2d9ff..0f76549 100644 --- a/custom_components/pun_sensor/__init__.py +++ b/custom_components/pun_sensor/__init__.py @@ -32,6 +32,7 @@ PUN_FASCIA_F1, PUN_FASCIA_F2, PUN_FASCIA_F3, + PZO, CONF_SCAN_HOUR, CONF_ACTUAL_DATA_ONLY, COORD_EVENT, @@ -150,8 +151,8 @@ def __init__(self, hass: HomeAssistant, config: ConfigEntry) -> None: # Inizializza i valori di default self.web_retries = 0 self.schedule_token = None - self.pun = [0.0, 0.0, 0.0, 0.0, 0.0] - self.orari = [0, 0, 0, 0, 0] + self.pun = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0] + self.orari = [0, 0, 0, 0, 0, 0] self.fascia_corrente = None self.prossimo_cambio_fascia = None self.termine_prossima_fascia = None @@ -229,6 +230,7 @@ async def _async_update_data(self): f1 = [] f2 = [] f3 = [] + pzo = [] # Esamina ogni file XML nello ZIP (ordinandoli prima) for fn in sorted(archive.namelist()): @@ -257,11 +259,17 @@ async def _async_update_data(self): prezzo_string = prezzo_string.replace('.','').replace(',','.') prezzo = float(prezzo_string) / 1000 + # Estrae il prezzo zonale orario nord dall'XML in un float + pzo_string = prezzi.find('NORD').text + pzo_string = pzo_string.replace('.','').replace(',','.') + pzo_float = float(pzo_string) / 1000 + # Estrae la fascia oraria fascia = get_fascia_for_xml(dat_date, festivo, ora) # Calcola le statistiche mono.append(prezzo) + pzo.append(pzo_float) if fascia == 3: f3.append(prezzo) elif fascia == 2: @@ -274,6 +282,7 @@ async def _async_update_data(self): self.orari[PUN_FASCIA_F1] = len(f1) self.orari[PUN_FASCIA_F2] = len(f2) self.orari[PUN_FASCIA_F3] = len(f3) + self.orari[PZO] = len(pzo) if self.orari[PUN_FASCIA_MONO] > 0: self.pun[PUN_FASCIA_MONO] = mean(mono) if self.orari[PUN_FASCIA_F1] > 0: @@ -282,6 +291,8 @@ async def _async_update_data(self): self.pun[PUN_FASCIA_F2] = mean(f2) if self.orari[PUN_FASCIA_F3] > 0: self.pun[PUN_FASCIA_F3] = mean(f3) + if self.orari[PZO] > 0: + self.pun[PZO] = mean(pzo) # Calcola la fascia F23 (a partire da F2 ed F3) # NOTA: la motivazione del calcolo è oscura ma sembra corretta; vedere: diff --git a/custom_components/pun_sensor/const.py b/custom_components/pun_sensor/const.py index 42f57e4..0f64f0f 100644 --- a/custom_components/pun_sensor/const.py +++ b/custom_components/pun_sensor/const.py @@ -7,6 +7,7 @@ PUN_FASCIA_F2 = 2 PUN_FASCIA_F3 = 3 PUN_FASCIA_F23 = 4 +PZO = 5 # Tipi di aggiornamento COORD_EVENT = "coordinator_event" diff --git a/custom_components/pun_sensor/sensor.py b/custom_components/pun_sensor/sensor.py index d567a8e..25c9f06 100644 --- a/custom_components/pun_sensor/sensor.py +++ b/custom_components/pun_sensor/sensor.py @@ -24,6 +24,7 @@ PUN_FASCIA_F1, PUN_FASCIA_F2, PUN_FASCIA_F3, + PZO ) from awesomeversion.awesomeversion import AwesomeVersion @@ -50,6 +51,7 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry, entities.append(PUNSensorEntity(coordinator, PUN_FASCIA_F1)) entities.append(PUNSensorEntity(coordinator, PUN_FASCIA_F2)) entities.append(PUNSensorEntity(coordinator, PUN_FASCIA_F3)) + entities.append(PUNSensorEntity(coordinator, PZO)) entities.append(FasciaPUNSensorEntity(coordinator)) entities.append(PrezzoFasciaPUNSensorEntity(coordinator)) @@ -100,6 +102,8 @@ def __init__(self, coordinator: PUNDataUpdateCoordinator, tipo: int) -> None: self.entity_id = ENTITY_ID_FORMAT.format('pun_mono_orario') elif (self.tipo == PUN_FASCIA_F23): self.entity_id = ENTITY_ID_FORMAT.format('pun_fascia_f23') + elif (self.tipo == PZO): + self.entity_id = ENTITY_ID_FORMAT.format('pzo') else: self.entity_id = None self._attr_unique_id = self.entity_id From 254d5b6f09a6a3e68cbecf8369957a982a2692b9 Mon Sep 17 00:00:00 2001 From: Gianluca Sullazzo Date: Wed, 25 Sep 2024 15:18:16 +0200 Subject: [PATCH 2/2] update manifest --- .vs/VSWorkspaceState.json | 6 + .vs/pun_sensor/config/applicationhost.config | 1021 ++++++++++++++++++ .vs/pun_sensor/v17/.wsuo | Bin 0 -> 12800 bytes .vs/pun_sensor/v17/DocumentLayout.json | 155 +++ .vs/slnx.sqlite | Bin 0 -> 90112 bytes custom_components/pun_sensor/manifest.json | 8 +- 6 files changed, 1186 insertions(+), 4 deletions(-) create mode 100644 .vs/VSWorkspaceState.json create mode 100644 .vs/pun_sensor/config/applicationhost.config create mode 100644 .vs/pun_sensor/v17/.wsuo create mode 100644 .vs/pun_sensor/v17/DocumentLayout.json create mode 100644 .vs/slnx.sqlite diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json new file mode 100644 index 0000000..6b61141 --- /dev/null +++ b/.vs/VSWorkspaceState.json @@ -0,0 +1,6 @@ +{ + "ExpandedNodes": [ + "" + ], + "PreviewInSolutionExplorer": false +} \ No newline at end of file diff --git a/.vs/pun_sensor/config/applicationhost.config b/.vs/pun_sensor/config/applicationhost.config new file mode 100644 index 0000000..269dc55 --- /dev/null +++ b/.vs/pun_sensor/config/applicationhost.config @@ -0,0 +1,1021 @@ + + + + + + + + +
+
+
+
+
+
+
+
+ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ + +
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.vs/pun_sensor/v17/.wsuo b/.vs/pun_sensor/v17/.wsuo new file mode 100644 index 0000000000000000000000000000000000000000..5d7385d64a94d5245e9b4e627f06fd4bf11cf466 GIT binary patch literal 12800 zcmeHNTXPge6z&935fu?cMZ|~^QJAoE+1(i|F@%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)$)#5b`2ac>+I{HyW}7pn{!E$h8u0D53ZjPx^lRoPP7HMyPOZHDl*!ablf83K2 z{R8a>-m>)aJlvVc?#@BB04?06gW9$|-3JkuU3gVk60GTEkICczakjB`p4|IV=AP4O zHVlU!8GNSWm|DDt7JELa!QlrSejI40<1v?Df z00e*l5C8%|00;nqr$Ydq|DO(bXcY(m0U!VbfB+Bx0zd!=00AHX1c1PkBmlqv_atdU zTR;E^00AHX1b_e#00KY&2mk>f00f>60XYAEI^3aEAOHk_01yBIKmZ5;0U!VbfB+Bx J0#A~_{{aL9yEp&< literal 0 HcmV?d00001 diff --git a/custom_components/pun_sensor/manifest.json b/custom_components/pun_sensor/manifest.json index 05f8c66..a85d90f 100644 --- a/custom_components/pun_sensor/manifest.json +++ b/custom_components/pun_sensor/manifest.json @@ -1,15 +1,15 @@ { "domain": "pun_sensor", "name": "Prezzi PUN del mese", - "codeowners": ["@virtualdj"], + "codeowners": [ "@virtualdj", "gianlucasullazzo" ], "config_flow": true, "dependencies": [], - "documentation": "https://github.com/virtualdj/pun_sensor", + "documentation": "https://github.com/gianlucasullazzo/pun_sensor", "import_executor": true, "integration_type": "hub", "iot_class": "cloud_polling", - "issue_tracker": "https://github.com/virtualdj/pun_sensor/issues", - "loggers": ["pun_sensor"], + "issue_tracker": "https://github.com/gianlucasullazzo/pun_sensor", + "loggers": [ "pun_sensor" ], "requirements": [], "single_config_entry": true, "version": "0.0.0"