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
c51170ef
Commit
c51170ef
authored
6 years ago
by
Fabian Affolter
Committed by
Martin Hjelmare
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add Volkszaehler sensor (#16188)
* Add Volkszaehler sensor * Update icons * Improve code
parent
9d491f53
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.coveragerc
+1
-0
1 addition, 0 deletions
.coveragerc
homeassistant/components/sensor/volkszaehler.py
+138
-0
138 additions, 0 deletions
homeassistant/components/sensor/volkszaehler.py
requirements_all.txt
+3
-0
3 additions, 0 deletions
requirements_all.txt
with
142 additions
and
0 deletions
.coveragerc
+
1
−
0
View file @
c51170ef
...
...
@@ -759,6 +759,7 @@ omit =
homeassistant/components/sensor/uscis.py
homeassistant/components/sensor/vasttrafik.py
homeassistant/components/sensor/viaggiatreno.py
homeassistant/components/sensor/volkszaehler.py
homeassistant/components/sensor/waqi.py
homeassistant/components/sensor/waze_travel_time.py
homeassistant/components/sensor/whois.py
...
...
This diff is collapsed.
Click to expand it.
homeassistant/components/sensor/volkszaehler.py
0 → 100644
+
138
−
0
View file @
c51170ef
"""
Support for consuming values for the Volkszaehler API.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.volkszaehler/
"""
from
datetime
import
timedelta
import
logging
import
voluptuous
as
vol
from
homeassistant.components.sensor
import
PLATFORM_SCHEMA
from
homeassistant.const
import
(
CONF_HOST
,
CONF_NAME
,
CONF_PORT
,
CONF_MONITORED_CONDITIONS
)
from
homeassistant.exceptions
import
PlatformNotReady
from
homeassistant.helpers.aiohttp_client
import
async_get_clientsession
import
homeassistant.helpers.config_validation
as
cv
from
homeassistant.helpers.entity
import
Entity
from
homeassistant.util
import
Throttle
REQUIREMENTS
=
[
'
volkszaehler==0.1.2
'
]
_LOGGER
=
logging
.
getLogger
(
__name__
)
CONF_UUID
=
'
uuid
'
DEFAULT_HOST
=
'
localhost
'
DEFAULT_NAME
=
'
Volkszaehler
'
DEFAULT_PORT
=
80
MIN_TIME_BETWEEN_UPDATES
=
timedelta
(
minutes
=
1
)
SENSOR_TYPES
=
{
'
average
'
:
[
'
Average
'
,
'
W
'
,
'
mdi:power-off
'
],
'
consumption
'
:
[
'
Consumption
'
,
'
Wh
'
,
'
mdi:power-plug
'
],
'
max
'
:
[
'
Max
'
,
'
W
'
,
'
mdi:arrow-up
'
],
'
min
'
:
[
'
Min
'
,
'
W
'
,
'
mdi:arrow-down
'
],
}
PLATFORM_SCHEMA
=
PLATFORM_SCHEMA
.
extend
({
vol
.
Required
(
CONF_UUID
):
cv
.
string
,
vol
.
Optional
(
CONF_HOST
,
default
=
DEFAULT_HOST
):
cv
.
string
,
vol
.
Optional
(
CONF_NAME
,
default
=
DEFAULT_NAME
):
cv
.
string
,
vol
.
Optional
(
CONF_PORT
,
default
=
DEFAULT_PORT
):
cv
.
port
,
vol
.
Optional
(
CONF_MONITORED_CONDITIONS
,
default
=
[
'
average
'
]):
vol
.
All
(
cv
.
ensure_list
,
[
vol
.
In
(
SENSOR_TYPES
)]),
})
async
def
async_setup_platform
(
hass
,
config
,
async_add_entities
,
discovery_info
=
None
):
"""
Set up the Volkszaehler sensors.
"""
from
volkszaehler
import
Volkszaehler
host
=
config
[
CONF_HOST
]
name
=
config
[
CONF_NAME
]
port
=
config
[
CONF_PORT
]
uuid
=
config
[
CONF_UUID
]
conditions
=
config
[
CONF_MONITORED_CONDITIONS
]
session
=
async_get_clientsession
(
hass
)
vz_api
=
VolkszaehlerData
(
Volkszaehler
(
hass
.
loop
,
session
,
uuid
,
host
=
host
,
port
=
port
))
await
vz_api
.
async_update
()
if
vz_api
.
api
.
data
is
None
:
raise
PlatformNotReady
dev
=
[]
for
condition
in
conditions
:
dev
.
append
(
VolkszaehlerSensor
(
vz_api
,
name
,
condition
))
async_add_entities
(
dev
,
True
)
class
VolkszaehlerSensor
(
Entity
):
"""
Implementation of a Volkszaehler sensor.
"""
def
__init__
(
self
,
vz_api
,
name
,
sensor_type
):
"""
Initialize the Volkszaehler sensor.
"""
self
.
vz_api
=
vz_api
self
.
_name
=
name
self
.
type
=
sensor_type
self
.
_state
=
None
@property
def
name
(
self
):
"""
Return the name of the sensor.
"""
return
'
{} {}
'
.
format
(
self
.
_name
,
SENSOR_TYPES
[
self
.
type
][
0
])
@property
def
icon
(
self
):
"""
Icon to use in the frontend, if any.
"""
return
SENSOR_TYPES
[
self
.
type
][
2
]
@property
def
unit_of_measurement
(
self
):
"""
Return the unit the value is expressed in.
"""
return
SENSOR_TYPES
[
self
.
type
][
1
]
@property
def
available
(
self
):
"""
Could the device be accessed during the last update call.
"""
return
self
.
vz_api
.
available
@property
def
state
(
self
):
"""
Return the state of the resources.
"""
return
self
.
_state
async
def
async_update
(
self
):
"""
Get the latest data from REST API.
"""
await
self
.
vz_api
.
async_update
()
if
self
.
vz_api
.
api
.
data
is
not
None
:
self
.
_state
=
round
(
getattr
(
self
.
vz_api
.
api
,
self
.
type
),
2
)
class
VolkszaehlerData
:
"""
The class for handling the data retrieval from the Volkszaehler API.
"""
def
__init__
(
self
,
api
):
"""
Initialize the data object.
"""
self
.
api
=
api
self
.
available
=
True
@Throttle
(
MIN_TIME_BETWEEN_UPDATES
)
async
def
async_update
(
self
):
"""
Get the latest data from the Volkszaehler REST API.
"""
from
volkszaehler.exceptions
import
VolkszaehlerApiConnectionError
try
:
await
self
.
api
.
get_data
()
self
.
available
=
True
except
VolkszaehlerApiConnectionError
:
_LOGGER
.
error
(
"
Unable to fetch data from the Volkszaehler API
"
)
self
.
available
=
False
This diff is collapsed.
Click to expand it.
requirements_all.txt
+
3
−
0
View file @
c51170ef
...
...
@@ -1431,6 +1431,9 @@ uvcclient==0.10.1
# homeassistant.components.climate.venstar
venstarcolortouch==0.6
# homeassistant.components.sensor.volkszaehler
volkszaehler==0.1.2
# homeassistant.components.config.config_entries
voluptuous-serialize==2.0.0
...
...
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