diff --git a/custom_components/octopus_spain/__init__.py b/custom_components/octopus_spain/__init__.py old mode 100644 new mode 100755 diff --git a/custom_components/octopus_spain/config_flow.py b/custom_components/octopus_spain/config_flow.py old mode 100644 new mode 100755 diff --git a/custom_components/octopus_spain/const.py b/custom_components/octopus_spain/const.py old mode 100644 new mode 100755 diff --git a/custom_components/octopus_spain/lib/octopus_spain.py b/custom_components/octopus_spain/lib/octopus_spain.py old mode 100644 new mode 100755 index 6704f09..c855c3d --- a/custom_components/octopus_spain/lib/octopus_spain.py +++ b/custom_components/octopus_spain/lib/octopus_spain.py @@ -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(), diff --git a/custom_components/octopus_spain/manifest.json b/custom_components/octopus_spain/manifest.json old mode 100644 new mode 100755 diff --git a/custom_components/octopus_spain/octopus_spain b/custom_components/octopus_spain/octopus_spain new file mode 120000 index 0000000..b59151f --- /dev/null +++ b/custom_components/octopus_spain/octopus_spain @@ -0,0 +1 @@ +octopus_spain \ No newline at end of file diff --git a/custom_components/octopus_spain/sensor.py b/custom_components/octopus_spain/sensor.py old mode 100644 new mode 100755 index 06f8523..125ce17 --- a/custom_components/octopus_spain/sensor.py +++ b/custom_components/octopus_spain/sensor.py @@ -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) @@ -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 @@ -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 diff --git a/custom_components/octopus_spain/strings.json b/custom_components/octopus_spain/strings.json old mode 100644 new mode 100755 diff --git a/custom_components/octopus_spain/translations/en.json b/custom_components/octopus_spain/translations/en.json old mode 100644 new mode 100755 diff --git a/custom_components/octopus_spain/translations/es.json b/custom_components/octopus_spain/translations/es.json old mode 100644 new mode 100755