-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Added support for Duke Energy smart meters #15165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
25c3275
e98c0a9
445ead8
c44fa30
b317b7b
4222321
c858cc5
f2731bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| """ | ||
| Support for Duke Energy Gas and Electric meters. | ||
|
|
||
| For more details about this component, please refer to the documentation at | ||
| https://home-assistant.io/components/sensor.duke_energy/ | ||
| """ | ||
| import logging | ||
|
|
||
| import voluptuous as vol | ||
|
|
||
| from homeassistant.components.sensor import PLATFORM_SCHEMA | ||
| from homeassistant.const import CONF_USERNAME, CONF_PASSWORD | ||
| from homeassistant.helpers.entity import Entity | ||
| import homeassistant.helpers.config_validation as cv | ||
|
|
||
| REQUIREMENTS = ['pydukeenergy==0.0.6'] | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ | ||
| vol.Required(CONF_USERNAME): cv.string, | ||
| vol.Required(CONF_PASSWORD): cv.string, | ||
| }) | ||
|
|
||
| LAST_BILL_USAGE = "last_bills_usage" | ||
| LAST_BILL_AVERAGE_USAGE = "last_bills_average_usage" | ||
| LAST_BILL_DAYS_BILLED = "last_bills_days_billed" | ||
|
|
||
|
|
||
| def setup_platform(hass, config, add_devices, discovery_info=None): | ||
| """Setup all Duke Energy meters.""" | ||
| from pydukeenergy.api import DukeEnergy, DukeEnergyException | ||
|
|
||
| try: | ||
| duke = DukeEnergy(config[CONF_USERNAME], | ||
| config[CONF_PASSWORD], | ||
| update_interval=120) | ||
| except DukeEnergyException: | ||
| _LOGGER.error("Failed to setup Duke Energy") | ||
| return | ||
|
|
||
| add_devices([DukeEnergyMeter(meter) for meter in duke.get_meters()]) | ||
|
|
||
|
|
||
| class DukeEnergyMeter(Entity): | ||
| """Representation of a Duke Energy meter.""" | ||
|
|
||
| def __init__(self, meter): | ||
| """Initialize the meter.""" | ||
| self.duke_meter = meter | ||
|
|
||
| @property | ||
| def name(self): | ||
| """Return the name.""" | ||
| return "duke_energy_{}".format(self.duke_meter.id) | ||
|
|
||
| @property | ||
| def unique_id(self): | ||
| """Return the unique ID.""" | ||
| return self.duke_meter.id | ||
|
|
||
| @property | ||
| def state(self): | ||
| """Return yesterdays usage.""" | ||
| return self.duke_meter.get_usage() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this doing I/O? No I/O in properties is allowed.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No all of the values are stored in a dict in the library and are only updated when update is called. |
||
|
|
||
| @property | ||
| def unit_of_measurement(self): | ||
| """Return the unit of measurement this sensor expresses itself in.""" | ||
| return self.duke_meter.get_unit() | ||
|
|
||
| @property | ||
| def device_state_attributes(self): | ||
| """Return the state attributes.""" | ||
| attributes = { | ||
| LAST_BILL_USAGE: self.duke_meter.get_total(), | ||
| LAST_BILL_AVERAGE_USAGE: self.duke_meter.get_average(), | ||
| LAST_BILL_DAYS_BILLED: self.duke_meter.get_days_billed() | ||
| } | ||
| return attributes | ||
|
|
||
| def update(self): | ||
| """Update meter.""" | ||
| self.duke_meter.update() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TokenError: EOF in multi-line string