Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
16865b82
Commit
16865b82
authored
9 years ago
by
infamy
Browse files
Options
Downloads
Patches
Plain Diff
initial commit of the neurio_energy sensor
parent
2ba3df22
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
homeassistant/components/sensor/neurio_energy.py
+87
-0
87 additions, 0 deletions
homeassistant/components/sensor/neurio_energy.py
requirements_all.txt
+3
-0
3 additions, 0 deletions
requirements_all.txt
with
90 additions
and
0 deletions
homeassistant/components/sensor/neurio_energy.py
0 → 100644
+
87
−
0
View file @
16865b82
"""
homeassistant.components.sensor.neurio_energy
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Monitors home energy use as measured by an neurio hub using its official API.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.neurio_energy/
"""
import
logging
import
requests.exceptions
from
homeassistant.helpers.entity
import
Entity
REQUIREMENTS
=
[
'
neurio==0.2.10
'
]
_LOGGER
=
logging
.
getLogger
(
__name__
)
ICON
=
'
mdi:flash
'
def
setup_platform
(
hass
,
config
,
add_devices
,
discovery_info
=
None
):
"""
Sets up the Neurio sensor.
"""
api_key
=
config
.
get
(
"
api_key
"
)
api_secret
=
config
.
get
(
"
api_secret
"
)
sensor_id
=
config
.
get
(
"
sensor_id
"
)
if
not
api_key
and
not
api_secret
:
_LOGGER
.
error
(
"
Configuration Error
"
"
Please make sure you have configured your api key and api secret
"
)
return
None
if
not
sensor_id
:
import
neurio
neurio_tp
=
neurio
.
TokenProvider
(
key
=
api_key
,
secret
=
api_secret
)
neurio_client
=
neurio
.
Client
(
token_provider
=
neurio_tp
)
user_info
=
neurio_client
.
get_user_information
()
_LOGGER
.
warning
(
'
Sensor ID auto-detected, set api_sensor_id:
"
%s
"'
,
user_info
[
"
locations
"
][
0
][
"
sensors
"
][
0
][
"
sensorId
"
])
sensor_id
=
user_info
[
"
locations
"
][
0
][
"
sensors
"
][
0
][
"
sensorId
"
]
dev
=
[]
dev
.
append
(
NeurioEnergy
(
api_key
,
api_secret
,
sensor_id
))
add_devices
(
dev
)
# pylint: disable=too-many-instance-attributes
class
NeurioEnergy
(
Entity
):
"""
Implements an Neurio energy.
"""
# pylint: disable=too-many-arguments
def
__init__
(
self
,
api_key
,
api_secret
,
sensor_id
):
self
.
_name
=
"
Energy Usage
"
self
.
api_key
=
api_key
self
.
api_secret
=
api_secret
self
.
sensor_id
=
sensor_id
self
.
_state
=
None
self
.
_unit_of_measurement
=
"
W
"
@property
def
name
(
self
):
"""
Returns the name.
"""
return
self
.
_name
@property
def
state
(
self
):
"""
Returns the state of the device.
"""
return
self
.
_state
@property
def
unit_of_measurement
(
self
):
"""
Unit of measurement of this entity, if any.
"""
return
self
.
_unit_of_measurement
@property
def
icon
(
self
):
"""
Icon to use in the frontend, if any.
"""
return
ICON
def
update
(
self
):
"""
Gets the Neurio monitor data from the web service.
"""
import
neurio
try
:
neurio_tp
=
neurio
.
TokenProvider
(
key
=
self
.
api_key
,
secret
=
self
.
api_secret
)
neurio_client
=
neurio
.
Client
(
token_provider
=
neurio_tp
)
sample
=
neurio_client
.
get_samples_live_last
(
sensor_id
=
self
.
sensor_id
)
self
.
_state
=
sample
[
'
consumptionPower
'
]
except
(
requests
.
exceptions
.
RequestException
,
ValueError
):
_LOGGER
.
warning
(
'
Could not update status for %s
'
,
self
.
name
)
This diff is collapsed.
Click to expand it.
requirements_all.txt
+
3
−
0
View file @
16865b82
...
...
@@ -115,6 +115,9 @@ mficlient==0.2.2
# homeassistant.components.discovery
netdisco==0.5.2
# homeassistant.components.sensor.neurio_energy
neurio==0.2.10
# homeassistant.components.switch.orvibo
orvibo==1.1.1
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment