Skip to content

Commit

Permalink
Fix integration
Browse files Browse the repository at this point in the history
Prevent duplicate accounts
Fix translation
Add brand icon
Update entry title to dsl/phone account
  • Loading branch information
Omar Raad committed Dec 1, 2023
1 parent 63a645f commit 7a061ec
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 75 deletions.
Binary file added assets/Ogero/ha-brand/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Ogero/ha-brand/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/Ogero/icon.png
Binary file not shown.
Binary file removed assets/Ogero/[email protected]
Binary file not shown.
33 changes: 25 additions & 8 deletions custom_components/ogero/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from __future__ import annotations

import voluptuous as vol
from homeassistant import config_entries
from homeassistant.config_entries import ConfigEntry, ConfigFlow, FlowResult
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import selector
from homeassistant.helpers.aiohttp_client import async_create_clientsession
from homeassistant.helpers.selector import (
Expand All @@ -18,13 +19,22 @@
OgeroApiClientAuthenticationError,
OgeroApiClientCommunicationError,
OgeroApiClientError,
Account,
)
from .const import DOMAIN, LOGGER

ACCOUNT = "account"

@callback
def configured_instances(hass: HomeAssistant) -> set[str]:
"""Return a set of configured instances."""
entries = []
for entry in hass.config_entries.async_entries(DOMAIN):
entries.append(entry.data.get(ACCOUNT))
return set(entries)

class OgeroFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):

class OgeroFlowHandler(ConfigFlow, domain=DOMAIN):
"""Config flow for Ogero."""

VERSION = 1
Expand All @@ -35,7 +45,7 @@ class OgeroFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
async def async_step_user(
self,
user_input: dict | None = None,
) -> config_entries.FlowResult:
) -> FlowResult:
"""Handle a flow initialized by the user."""
_errors = {}
if user_input is not None:
Expand Down Expand Up @@ -82,14 +92,21 @@ async def async_step_user(
async def async_step_account(
self,
user_input: dict | None = None,
) -> config_entries.FlowResult:
) -> FlowResult:
"""Handle a flow initialized by the user."""
_errors = {}
if user_input is not None:
return self.async_create_entry(
title=self._user_data[CONF_USERNAME],
data={**self._user_data, **user_input},
)
is_predefined = user_input[ACCOUNT] in configured_instances(self.hass)

if is_predefined:
_errors[ACCOUNT] = "account_already_configured"

if len(_errors) == 0:
account = Account.deserialize(user_input[ACCOUNT])
return self.async_create_entry(
title=str(account),
data={**self._user_data, **user_input},
)

accounts = await self._get_accounts("", "")

Expand Down
2 changes: 1 addition & 1 deletion custom_components/ogero/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

NAME = "Ogero"
DOMAIN = "ogero"
VERSION = "0.2.0"
VERSION = "0.3.0"
ATTRIBUTION = "Data retrieved from https://ogero.gov.lb/"
1 change: 1 addition & 0 deletions custom_components/ogero/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class OgeroEntity(CoordinatorEntity[OgeroDataUpdateCoordinator]):
"""OgeroEntity class."""

_attr_attribution = ATTRIBUTION
_attr_has_entity_name = True

def __init__(self, coordinator: OgeroDataUpdateCoordinator, name: str) -> None:
"""Initialize."""
Expand Down
2 changes: 1 addition & 1 deletion custom_components/ogero/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"requirements": [
"pyogero==0.7.0"
],
"version": "0.2.0"
"version": "0.3.0"
}
26 changes: 8 additions & 18 deletions custom_components/ogero/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,47 +28,47 @@
ENTITY_DESCRIPTIONS = (
SensorEntityDescription(
key=QUOTA,
name=QUOTA,
translation_key=QUOTA,
native_unit_of_measurement="GB",
suggested_display_precision=0,
icon="mdi:format-quote-close",
),
SensorEntityDescription(
key=SPEED,
name=SPEED,
translation_key=SPEED,
icon="mdi:speedometer",
),
SensorEntityDescription(
key=DOWNLOAD,
name=DOWNLOAD,
translation_key=DOWNLOAD,
native_unit_of_measurement="GB",
suggested_display_precision=1,
icon="mdi:download",
),
SensorEntityDescription(
key=UPLOAD,
name=UPLOAD,
translation_key=UPLOAD,
native_unit_of_measurement="GB",
suggested_display_precision=1,
icon="mdi:upload",
),
SensorEntityDescription(
key=TOTAL_CONSUMPTION,
name=TOTAL_CONSUMPTION,
translation_key=TOTAL_CONSUMPTION,
native_unit_of_measurement="GB",
suggested_display_precision=1,
icon="mdi:sigma",
),
SensorEntityDescription(
key=EXTRA_CONSUMPTION,
name=EXTRA_CONSUMPTION,
translation_key=EXTRA_CONSUMPTION,
native_unit_of_measurement="GB",
suggested_display_precision=1,
icon="mdi:alert",
),
SensorEntityDescription(
key=LAST_UPDATE,
name=LAST_UPDATE,
translation_key=LAST_UPDATE,
device_class=SensorDeviceClass.TIMESTAMP,
icon="mdi:update",
),
Expand All @@ -77,7 +77,7 @@
EXTENDED_ENTITY_DESCRIPTIONS = (
SensorEntityDescription(
key=OUTSTANDING_BALANCE,
name=OUTSTANDING_BALANCE,
translation_key=OUTSTANDING_BALANCE,
device_class=SensorDeviceClass.MONETARY,
native_unit_of_measurement="LBP",
),
Expand Down Expand Up @@ -140,13 +140,3 @@ def native_value(self) -> str:
self._attr_extra_state_attributes[key] = value

return self.coordinator.data.get(self.entity_description.key)

# async def async_update(self):
# attributes = self.coordinator.data.get("state_attributes").get(
# self.entity_description.key
# )

# for attribute in attributes:
# key, value = attribute
# LOGGER.debug("attribute key: %s, value: %s", key, value)
# self._attr_extra_state_attributes[key] = value
46 changes: 0 additions & 46 deletions custom_components/ogero/strings.json

This file was deleted.

10 changes: 9 additions & 1 deletion custom_components/ogero/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@
"username": "Username",
"password": "Password"
}
},
"account": {
"description": "If you need help with the configuration have a look here: https://github.com/oraad/ha-ogero",
"data": {
"account": "Account"
}
}
},
"abort": {},
"error": {
"auth": "Username/Password is wrong.",
"connection": "Unable to connect to the server.",
"unknown": "Unknown error occurred."
"unknown": "Unknown error occurred.",
"account_already_configured": "Account is already configured"
}
},
"entity": {
Expand Down

0 comments on commit 7a061ec

Please sign in to comment.