Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
#14 remove the Customer information sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
toringer committed Aug 13, 2022
1 parent db154af commit e8c7336
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 98 deletions.
90 changes: 0 additions & 90 deletions custom_components/sbanken/sbanken_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,93 +152,3 @@ async def async_update(self):
f"Error updating payments {self._attr_name}. Payments: {str(payments)}"
)


class CustomerInformationSensor(Entity):
"""Representation of a Sensor."""

def __init__(
self,
api: SbankenApi,
hass: HomeAssistant,
customer_id: str,
) -> None:
"""Initialize the sensor."""
self.api = api
self.hass = hass
self._customer_id = customer_id
self._attr_unique_id = self._customer_id
self._attr_name = "Customer information"
self._attr_icon = "mdi:information-outline"
self._email_address = ""
self._date_of_birth = None
self._postal_address = None
self._street_address = None
self._phone_numbers = None
self._first_name = ""
self._last_name = ""
self._last_updated = datetime.now()

@property
def device_info(self):
"""Return the device_info of the device."""
device_info = DeviceInfo(
identifiers={(DOMAIN, self._customer_id)},
name=f"Sbanken: {self._first_name} {self._last_name}",
manufacturer="Sbanken",
configuration_url="https://sbanken.no/",
)
return device_info

@property
def state(self):
"""Return the state of the sensor."""
return f"{self._first_name} {self._last_name}"

@property
def extra_state_attributes(self):
"""Return the state attributes."""
return {
"customerId": self._customer_id,
"firstName": self._first_name,
"lastName": self._last_name,
"emailAddress": self._email_address,
"dateOfBirth": self._date_of_birth,
"postalAddress": self._postal_address,
"streetAddress": self._street_address,
"phoneNumbers": self._phone_numbers,
ATTR_LAST_UPDATE: self._last_updated,
}

async def async_update(self):
"""Fetch new state data for the sensor.
This is the only method that should fetch new data for Home Assistant.
"""
customer_info = await self.hass.async_add_executor_job(
self.api.get_customer_information
)

if (
"customerId" in customer_info
and "emailAddress" in customer_info
and "dateOfBirth" in customer_info
and "postalAddress" in customer_info
and "streetAddress" in customer_info
and "phoneNumbers" in customer_info
and "firstName" in customer_info
and "lastName" in customer_info
):
self._customer_id = customer_info["customerId"]
self._email_address = customer_info["emailAddress"]
self._date_of_birth = customer_info["dateOfBirth"]
self._postal_address = customer_info["postalAddress"]
self._street_address = customer_info["streetAddress"]
self._phone_numbers = customer_info["phoneNumbers"]
self._first_name = customer_info["firstName"]
self._last_name = customer_info["lastName"]
self._last_updated = datetime.now()
_LOGGER.debug(f"Updating customer information: {self._attr_name}")
else:
_LOGGER.warn(
f"Error updating customer information: {self._attr_name}. Data{str(customer_info)}"
)
9 changes: 1 addition & 8 deletions custom_components/sbanken/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .services import async_setup_services
from .sbanken_api import SbankenApi
from .sbanken_entities import SbankenAccountSensor, CustomerInformationSensor
from .sbanken_entities import SbankenAccountSensor
from .const import CONF_NUMBER_OF_TRANSACTIONS, DOMAIN


Expand Down Expand Up @@ -36,12 +36,5 @@ async def async_setup_entry(
)
for account in accounts
]
sensors.append(
CustomerInformationSensor(
api,
hass,
customer_info["customerId"],
)
)
async_add_entities(sensors, update_before_add=True)
await async_setup_services(hass, sensors)

0 comments on commit e8c7336

Please sign in to comment.