Skip to content

Commit

Permalink
Añadido credito
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelAngelLV committed Jan 7, 2024
1 parent 5707a99 commit 9c92b4d
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 8 deletions.
Empty file modified custom_components/octopus_spain/__init__.py
100644 → 100755
Empty file.
Empty file modified custom_components/octopus_spain/config_flow.py
100644 → 100755
Empty file.
Empty file modified custom_components/octopus_spain/const.py
100644 → 100755
Empty file.
3 changes: 2 additions & 1 deletion custom_components/octopus_spain/lib/octopus_spain.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ async def account(self, account: str):

# Los timedelta son bastante chapuzas, habrá que arreglarlo
return {
"solar_wallet": (float(solar_wallet["balance"]) / 100) if solar_wallet else 0,
"solar_wallet": (float(solar_wallet["balance"]) / 100),
"octopus_credit": (float(electricity["balance"]) / 100),
"last_invoice": {
"amount": invoice["amount"] if invoice["amount"] else 0,
"issued": datetime.fromisoformat(invoice["issuedDate"]).date(),
Expand Down
Empty file modified custom_components/octopus_spain/manifest.json
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions custom_components/octopus_spain/octopus_spain
16 changes: 9 additions & 7 deletions custom_components/octopus_spain/sensor.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_e

accounts = coordinator.data.keys()
for account in accounts:
sensors.append(OctopusSolarWallet(account, coordinator, len(accounts) == 1))
sensors.append(OctopusWallet(account, 'solar_wallet', 'Solar Wallet', coordinator, len(accounts) == 1))
sensors.append(OctopusWallet(account, 'octopus_credit', 'Octopus Credit', coordinator, len(accounts) == 1))
sensors.append(OctopusInvoice(account, coordinator, len(accounts) == 1))

async_add_entities(sensors)
Expand All @@ -58,17 +59,18 @@ async def _async_update_data(self):
return self._data


class OctopusSolarWallet(CoordinatorEntity, SensorEntity):
class OctopusWallet(CoordinatorEntity, SensorEntity):

def __init__(self, account: str, coordinator, single: bool):
def __init__(self, account: str, key: str, name: str, coordinator, single: bool):
super().__init__(coordinator=coordinator)
self._state = None
self._key = key
self._account = account
self._attrs: Mapping[str, Any] = {}
self._attr_name = "Solar Wallet" if single else f"Solar Wallet ({account})"
self._attr_unique_id = f"solar_wallet_{account}"
self._attr_name = f"{name}" if single else f"{name} ({account})"
self._attr_unique_id = f"{key}_{account}"
self.entity_description = SensorEntityDescription(
key=f"solar_wallet_{account}",
key=f"{key}_{account}",
icon="mdi:piggy-bank-outline",
native_unit_of_measurement=CURRENCY_EURO,
state_class=STATE_CLASS_MEASUREMENT
Expand All @@ -81,7 +83,7 @@ async def async_added_to_hass(self) -> None:
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
self._state = self.coordinator.data[self._account]['solar_wallet']
self._state = self.coordinator.data[self._account][self._key]
self.async_write_ha_state()

@property
Expand Down
Empty file modified custom_components/octopus_spain/strings.json
100644 → 100755
Empty file.
Empty file modified custom_components/octopus_spain/translations/en.json
100644 → 100755
Empty file.
Empty file modified custom_components/octopus_spain/translations/es.json
100644 → 100755
Empty file.

0 comments on commit 9c92b4d

Please sign in to comment.