Skip to content
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

new release #58

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ExpandedNodes": [
""
],
"PreviewInSolutionExplorer": false
}
1,021 changes: 1,021 additions & 0 deletions .vs/pun_sensor/config/applicationhost.config

Large diffs are not rendered by default.

Binary file added .vs/pun_sensor/v17/.wsuo
Binary file not shown.
155 changes: 155 additions & 0 deletions .vs/pun_sensor/v17/DocumentLayout.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
{
"Version": 1,
"WorkspaceRootPath": "D:\\gs_git\\gianlucasullazzo\\pun_sensor\\",
"Documents": [],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": [
{
"DockedWidth": 200,
"SelectedChildIndex": -1,
"Children": [
{
"$type": "Bookmark",
"Name": "ST:0:0:{65ddf8c3-8f89-4077-a6c6-dbb8853aab13}"
},
{
"$type": "Bookmark",
"Name": "ST:23:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:21:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:19:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:20:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:17:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:130:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
},
{
"$type": "Bookmark",
"Name": "ST:131:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
},
{
"$type": "Bookmark",
"Name": "ST:132:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
},
{
"$type": "Bookmark",
"Name": "ST:18:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:27:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:29:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:30:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:16:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:33:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:34:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:35:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:45:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:37:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:38:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:39:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:41:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:42:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:44:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:40:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:43:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:46:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:36:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:129:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
},
{
"$type": "Bookmark",
"Name": "ST:15:0:{2456bd12-ecf7-4988-a4a6-67d49173f565}"
},
{
"$type": "Bookmark",
"Name": "ST:131:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
},
{
"$type": "Bookmark",
"Name": "ST:132:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
},
{
"$type": "Bookmark",
"Name": "ST:128:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
},
{
"$type": "Bookmark",
"Name": "ST:0:0:{99b8fa2f-ab90-4f57-9c32-949f146f1914}"
}
]
}
]
}
]
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
15 changes: 13 additions & 2 deletions custom_components/pun_sensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
PUN_FASCIA_F1,
PUN_FASCIA_F2,
PUN_FASCIA_F3,
PZO,
CONF_SCAN_HOUR,
CONF_ACTUAL_DATA_ONLY,
COORD_EVENT,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()):
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions custom_components/pun_sensor/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions custom_components/pun_sensor/manifest.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 4 additions & 0 deletions custom_components/pun_sensor/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
PUN_FASCIA_F1,
PUN_FASCIA_F2,
PUN_FASCIA_F3,
PZO
)

from awesomeversion.awesomeversion import AwesomeVersion
Expand All @@ -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))

Expand Down Expand Up @@ -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
Expand Down