-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from tijsverkoyen/more-entities
More entities
- Loading branch information
Showing
7 changed files
with
519 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from homeassistant.helpers.entity import Entity, EntityCategory, DeviceInfo | ||
|
||
from .energy_id.record import EnergyIDRecord | ||
|
||
from .const import DOMAIN | ||
|
||
|
||
class EnergyIDDiagnosticEntity(Entity): | ||
def __init__( | ||
self, | ||
device, | ||
name: str, | ||
attribute: str, | ||
value, | ||
icon: str = None, | ||
): | ||
"""Initialize the entity""" | ||
self._device = device | ||
self._name = name | ||
self._attribute = attribute | ||
self._value = value | ||
self._icon = icon | ||
|
||
@property | ||
def name(self) -> str: | ||
return f'{self._device.display_name} - {self._name}' | ||
|
||
@property | ||
def state(self): | ||
return self._value | ||
|
||
@property | ||
def device_info(self) -> DeviceInfo: | ||
return self._device.device_info | ||
|
||
@property | ||
def entity_category(self) -> str: | ||
return EntityCategory.DIAGNOSTIC | ||
|
||
@property | ||
def should_poll(self) -> bool: | ||
return False | ||
|
||
@property | ||
def icon(self) -> str: | ||
return self._icon | ||
|
||
|
||
class EnergyIDRecordDiagnosticEntity(EnergyIDDiagnosticEntity): | ||
@property | ||
def unique_id(self) -> str: | ||
return f'{DOMAIN}-{self._device.record_id}-{self._attribute}' | ||
|
||
|
||
class EnergyIDMeterDiagnosticEntity(EnergyIDDiagnosticEntity): | ||
@property | ||
def unique_id(self) -> str: | ||
return f'{DOMAIN}-{self._device.meter_id}-{self._attribute}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,125 @@ | ||
from homeassistant.helpers.entity import DeviceInfo | ||
from ..const import DOMAIN | ||
|
||
import datetime | ||
|
||
|
||
class EnergyIDMeter: | ||
def __init__( | ||
self, | ||
id: str, | ||
record_id: str, | ||
name: str, | ||
automatic: bool, | ||
display_name: str, | ||
exclude_from_reports: bool, | ||
hidden: bool, | ||
meter_id: str, | ||
meter_type: str, | ||
metric: str, | ||
multiplier: float, | ||
reading_type: str, | ||
record_id: str, | ||
theme: str, | ||
unit: str | ||
unit: str, | ||
integration_id: str = None, | ||
activated: datetime = None, | ||
deactivated: datetime = None, | ||
comments: str = None, | ||
confirmed: bool = None, | ||
installation_number: str = None, | ||
connection_number: str = None, | ||
supplier: str = None, | ||
renewable: bool = None, | ||
brand_name: str = None, | ||
model_name: str = None, | ||
peak_power: float = None, | ||
meter_number: str = None, | ||
stock_capacity: int = None, | ||
interval: str = None, | ||
qr_key: str = None, | ||
qr_type: str = None | ||
): | ||
self.id = id | ||
self.record_id = record_id | ||
self.name = name | ||
self.automatic = automatic | ||
self.display_name = display_name | ||
self.exclude_from_reports = exclude_from_reports | ||
self.hidden = hidden | ||
self.meter_id = meter_id | ||
self.meter_type = meter_type | ||
self.metric = metric | ||
self.multiplier = multiplier | ||
self.reading_type = reading_type | ||
self.record_id = record_id | ||
self.theme = theme | ||
self.unit = unit | ||
self.state = None | ||
self.last_updated = None | ||
self.last_updated_str = None | ||
self.integration_id = integration_id | ||
self.activated = activated | ||
self.deactivated = deactivated | ||
self.comments = comments | ||
self.confirmed = confirmed | ||
self.installation_number = installation_number | ||
self.connection_number = connection_number | ||
self.supplier = supplier | ||
self.renewable = renewable | ||
self.brand_name = brand_name | ||
self.model_name = model_name | ||
self.peak_power = peak_power | ||
self.meter_number = meter_number | ||
self.stock_capacity = stock_capacity | ||
self.interval = interval | ||
self.qr_key = qr_key | ||
self.qr_type = qr_type | ||
|
||
@classmethod | ||
def from_json(cls, json): | ||
return cls( | ||
automatic=json['automatic'], | ||
display_name=json['displayName'], | ||
exclude_from_reports=json['excludeFromReports'], | ||
hidden=json['hidden'], | ||
meter_id=json['id'], | ||
meter_type=json['meterType'], | ||
metric=json['metric'], | ||
multiplier=json['multiplier'], | ||
reading_type=json['readingType'], | ||
record_id=json['recordId'], | ||
theme=json['theme'], | ||
unit=json['unit'], | ||
integration_id=json['integrationId'] if 'integrationId' in json else None, | ||
activated=json['activated'] if 'activated' in json else None, | ||
deactivated=json['deactivated'] if 'deactivated' in json else None, | ||
comments=json['comments'] if 'comments' in json else None, | ||
confirmed=json['confirmed'] if 'confirmed' in json else None, | ||
installation_number=json['installationNumber'] if 'installationNumber' in json else None, | ||
connection_number=json['connectionNumber'] if 'connectionNumber' in json else None, | ||
supplier=json['supplier'] if 'supplier' in json else None, | ||
renewable=json['renewable'] if 'renewable' in json else None, | ||
brand_name=json['brandName'] if 'brandName' in json else None, | ||
model_name=json['modelName'] if 'modelName' in json else None, | ||
peak_power=json['peakPower'] if 'peakPower' in json else None, | ||
meter_number=json['meterNumber'] if 'meterNumber' in json else None, | ||
stock_capacity=json['stockCapacity'] if 'stockCapacity' in json else None, | ||
interval=json['interval'] if 'interval' in json else None, | ||
qr_key=json['qrKey'] if 'qrKey' in json else None, | ||
qr_type=json['qrType'] if 'qrType' in json else None | ||
) | ||
|
||
@property | ||
def device_info(self) -> DeviceInfo: | ||
manufacturer = 'EnergyID' | ||
|
||
if self.supplier is not None: | ||
manufacturer = self.supplier | ||
|
||
if self.brand_name is not None: | ||
manufacturer = self.brand_name | ||
|
||
model = self.meter_type | ||
if self.model_name is not None: | ||
model = self.meter_type + " " + self.model_name | ||
|
||
return DeviceInfo( | ||
configuration_url=f'https://app.energyid.eu/record/{self.record_id}/meters/{self.meter_id}/properties', | ||
identifiers={(DOMAIN, f'meter-{self.meter_id}')}, | ||
name=self.display_name, | ||
manufacturer=manufacturer, | ||
model=model, | ||
via_device=(DOMAIN, f'record-{self.record_id}') | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,146 @@ | ||
from homeassistant.helpers.entity import DeviceInfo | ||
from ..const import DOMAIN | ||
|
||
import datetime | ||
|
||
|
||
class EnergyIDAddress: | ||
def __init__( | ||
self, | ||
street: str = None, | ||
postal_code: str = None, | ||
city: str = None, | ||
country: str = None, | ||
): | ||
self.street = street | ||
self.postal_code = postal_code | ||
self.city = city | ||
self.country = country | ||
|
||
|
||
class EnergyIDRecord: | ||
def __init__( | ||
self, | ||
id: str, | ||
number: str, | ||
name: str, | ||
created: datetime, | ||
display_name: str, | ||
record_id: str, | ||
owner_id: str, | ||
record_number: str, | ||
record_type: str, | ||
time_zone: str, | ||
last_submission: datetime = None, | ||
address: EnergyIDAddress = None, | ||
category: str = None, | ||
tags: list = None, | ||
dwelling_type: str = None, | ||
principal_residence: bool = None, | ||
occupants: int = None, | ||
occupier_type: str = None, | ||
heating_on: str = None, | ||
auxiliary_heating_on: str = None, | ||
cooking_on: str = None, | ||
hot_water_on: str = None, | ||
floor_surface: float = None, | ||
year_of_construction: int = None, | ||
year_of_renovation: int = None, | ||
energy_performance: float = None, | ||
energy_rating: float = None, | ||
energy_efficiency: str = None, | ||
installations: list = None, | ||
plan: str = None, | ||
errors: int = None, | ||
benchmarking_enabled: bool = None, | ||
premium_features: list = None, | ||
): | ||
self.id = id | ||
self.number = number | ||
self.name = name | ||
self.created = created | ||
self.display_name = display_name | ||
self.record_id = record_id | ||
self.owner_id = owner_id | ||
self.record_number = record_number | ||
self.record_type = record_type | ||
self.time_zone = time_zone | ||
self.last_submission = last_submission | ||
self.address = address | ||
self.category = category | ||
self.tags = tags | ||
self.dwelling_type = dwelling_type | ||
self.principal_residence = principal_residence | ||
self.occupants = occupants | ||
self.occupier_type = occupier_type | ||
self.heating_on = heating_on | ||
self.auxiliary_heating_on = auxiliary_heating_on | ||
self.cooking_on = cooking_on | ||
self.hot_water_on = hot_water_on | ||
self.floor_surface = floor_surface | ||
self.year_of_construction = year_of_construction | ||
self.year_of_renovation = year_of_renovation | ||
self.energy_performance = energy_performance | ||
self.energy_rating = energy_rating | ||
self.energy_efficiency = energy_efficiency | ||
self.installations = installations | ||
self.plan = plan | ||
self.errors = errors | ||
self.benchmarking_enabled = benchmarking_enabled | ||
self.premium_features = premium_features | ||
|
||
@classmethod | ||
def from_json(cls, json): | ||
address = None | ||
if 'address' in json: | ||
address = EnergyIDAddress( | ||
json['address']['streetAddress'], | ||
json['address']['postalCode'], | ||
json['address']['city'], | ||
json['address']['country'] | ||
) | ||
|
||
created = None | ||
if 'created' in json and json['created']: | ||
created = datetime.datetime.strptime(json['created'], '%Y-%m-%dT%H:%M:%S.%fZ') | ||
|
||
last_submission = None | ||
if 'lastSubmission' in json and json['lastSubmission'] is not None: | ||
last_submission = datetime.datetime.strptime(json['lastSubmission'], '%Y-%m-%dT%H:%M:%SZ') | ||
|
||
return cls( | ||
created=created, | ||
display_name=json['displayName'], | ||
record_id=json['id'], | ||
owner_id=json['ownerId'], | ||
record_number=json['recordNumber'], | ||
record_type=json['recordType'], | ||
time_zone=json['timeZone'], | ||
last_submission=last_submission, | ||
address=address, | ||
category=json['category'] if 'category' in json else None, | ||
tags=json['tags'] if 'tags' in json else None, | ||
dwelling_type=json['dwellingType'] if 'dwellingType' in json else None, | ||
principal_residence=json['principalResidence'] if 'principalResidence' in json else None, | ||
occupants=json['occupants'] if 'occupants' in json else None, | ||
occupier_type=json['occupierType'] if 'occupierType' in json else None, | ||
heating_on=json['heatingOn'] if 'heatingOn' in json else None, | ||
auxiliary_heating_on=json['auxiliaryHeatingOn'] if 'auxiliaryHeatingOn' in json else None, | ||
cooking_on=json['cookingOn'] if 'cookingOn' in json else None, | ||
hot_water_on=json['hotWaterOn'] if 'hotWaterOn' in json else None, | ||
floor_surface=json['floorSurface'] if 'floorSurface' in json else None, | ||
year_of_construction=json['yearOfConstruction'] if 'yearOfConstruction' in json else None, | ||
year_of_renovation=json['yearOfRenovation'] if 'yearOfRenovation' in json else None, | ||
energy_performance=json['energyPerformance'] if 'energyPerformance' in json else None, | ||
energy_rating=json['energyRating'] if 'energyRating' in json else None, | ||
energy_efficiency=json['energyEfficiency'] if 'energyEfficiency' in json else None, | ||
installations=json['installations'] if 'installations' in json else None, | ||
plan=json['plan'] if 'plan' in json else None, | ||
errors=json['errors'] if 'errors' in json else None, | ||
benchmarking_enabled=json['benchmarkingEnabled'] if 'benchmarkingEnabled' in json else None, | ||
premium_features=json['premiumFeatures'] if 'premiumFeatures' in json else None, | ||
) | ||
|
||
@property | ||
def device_info(self) -> DeviceInfo: | ||
return DeviceInfo( | ||
configuration_url=f'https://app.energyid.eu/record/{self.record_number}/facility', | ||
identifiers={(DOMAIN, f'record-{self.record_id}')}, | ||
name=self.display_name, | ||
manufacturer="EnergyID", | ||
model="Record", | ||
) |
Oops, something went wrong.