Skip to content
Open
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
13 changes: 7 additions & 6 deletions custom_components/tarif_edf/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,19 @@ async def _async_update_data(self) -> dict[Platform, dict[str, Any]]:
response = await self.hass.async_add_executor_job(get_remote_file, url)
parsed_content = csv.reader(response.content.decode('utf-8').splitlines(), delimiter=';')
rows = list(parsed_content)
today = date.today()

for row in rows:
if row[1] == '' and row[2] == data['contract_power']:
for row in reversed(rows): #On part de la fin
if row[0] != "" and today >= datetime.strptime(row[0], "%d/%m/%Y").date() and row[2] == data['contract_power']:
if data['contract_type'] == CONTRACT_TYPE_BASE:
self.data['base_fixe_ttc'] = float(row[4].replace(",", "." ))
self.data['base_fixe_ttc'] = float(row[4].replace(",", "." )) /12
self.data['base_variable_ttc'] = float(row[6].replace(",", "." ))
elif data['contract_type'] == CONTRACT_TYPE_HPHC:
self.data['hphc_fixe_ttc'] = float(row[4].replace(",", "." ))
elif data['contract_type'] == CONTRACT_TYPE_HPHC:
self.data['hphc_fixe_ttc'] = float(row[4].replace(",", "." )) /12
self.data['hphc_variable_hc_ttc'] = float(row[6].replace(",", "." ))
self.data['hphc_variable_hp_ttc'] = float(row[8].replace(",", "." ))
elif data['contract_type'] == CONTRACT_TYPE_TEMPO:
self.data['tempo_fixe_ttc'] = float(row[4].replace(",", "." ))
self.data['tempo_fixe_ttc'] = float(row[4].replace(",", "." )) /12
self.data['tempo_variable_hc_bleu_ttc'] = float(row[6].replace(",", "." ))
self.data['tempo_variable_hp_bleu_ttc'] = float(row[8].replace(",", "." ))
self.data['tempo_variable_hc_blanc_ttc'] = float(row[10].replace(",", "." ))
Expand Down
7 changes: 5 additions & 2 deletions custom_components/tarif_edf/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ async def async_setup_entry(
if coordinator.data['contract_type'] == CONTRACT_TYPE_BASE:
sensors.extend([
TarifEdfSensor(coordinator, 'base_variable_ttc', 'Tarif Base TTC', 'EUR/kWh'),
TarifEdfSensor(coordinator, 'base_fixe_ttc', 'Tarif Abonnement Base TTC', 'EUR/mois'),
])
elif coordinator.data['contract_type'] == CONTRACT_TYPE_HPHC:
sensors.extend([
TarifEdfSensor(coordinator, 'hphc_variable_hc_ttc', 'Tarif Heures creuses TTC', 'EUR/kWh'),
TarifEdfSensor(coordinator, 'hphc_variable_hp_ttc', 'Tarif Heures pleines TTC', 'EUR/kWh'),
TarifEdfSensor(coordinator, 'hphc_fixe_ttc', 'Tarif Abonnement HPHC TTC', 'EUR/mois'),
])
elif coordinator.data['contract_type'] == CONTRACT_TYPE_TEMPO:
sensors.extend([
Expand All @@ -56,6 +58,7 @@ async def async_setup_entry(
TarifEdfSensor(coordinator, 'tempo_variable_hp_rouge_ttc', 'Tarif Rouge Tempo Heures pleines TTC', 'EUR/kWh'),
TarifEdfSensor(coordinator, 'tempo_variable_hc_blanc_ttc', 'Tarif Blanc Tempo Heures creuses TTC', 'EUR/kWh'),
TarifEdfSensor(coordinator, 'tempo_variable_hp_blanc_ttc', 'Tarif Blanc Tempo Heures pleines TTC', 'EUR/kWh'),
TarifEdfSensor(coordinator, 'tempo_fixe_ttc', 'Tarif Abonnement Tempo TTC', 'EUR/mois'),
])

if coordinator.data['tarif_actuel_ttc'] is not None:
Expand Down Expand Up @@ -87,7 +90,7 @@ def __init__(self, coordinator, coordinator_key: str, name: str, unit_of_measure
model=contract_name,
)
if (unit_of_measurement is not None):
self._attr_unit_of_measurement = unit_of_measurement
self._attr_native_unit_of_measurement = unit_of_measurement

@property
def native_value(self):
Expand All @@ -102,7 +105,7 @@ def extra_state_attributes(self):
"""Return the state attributes."""
return {
'updated_at': self.coordinator.last_update_success_time,
'unit_of_measurement': self._attr_unit_of_measurement,
'unit_of_measurement': self._attr_native_unit_of_measurement,
}

@property
Expand Down