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
4314dc25
Commit
4314dc25
authored
7 years ago
by
Daniel Høyer Iversen
Committed by
Fabian Affolter
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add Tibber sensor (#9661)
* Add Tibber sensor * remove extra space
parent
e0de5213
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/tibber.py
+99
-0
99 additions, 0 deletions
homeassistant/components/sensor/tibber.py
requirements_all.txt
+3
-0
3 additions, 0 deletions
requirements_all.txt
with
103 additions
and
0 deletions
.coveragerc
+
1
−
0
View file @
4314dc25
...
...
@@ -541,6 +541,7 @@ omit =
homeassistant/components/sensor/tank_utility.py
homeassistant/components/sensor/ted5000.py
homeassistant/components/sensor/temper.py
homeassistant/components/sensor/tibber.py
homeassistant/components/sensor/time_date.py
homeassistant/components/sensor/torque.py
homeassistant/components/sensor/transmission.py
...
...
This diff is collapsed.
Click to expand it.
homeassistant/components/sensor/tibber.py
0 → 100644
+
99
−
0
View file @
4314dc25
"""
Support for Tibber.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.tibber/
"""
import
asyncio
import
logging
from
datetime
import
timedelta
import
voluptuous
as
vol
import
homeassistant.helpers.config_validation
as
cv
from
homeassistant.components.sensor
import
PLATFORM_SCHEMA
from
homeassistant.const
import
CONF_ACCESS_TOKEN
from
homeassistant.helpers.aiohttp_client
import
async_get_clientsession
from
homeassistant.helpers.entity
import
Entity
from
homeassistant.util
import
dt
as
dt_util
REQUIREMENTS
=
[
'
pyTibber==0.1.1
'
]
_LOGGER
=
logging
.
getLogger
(
__name__
)
PLATFORM_SCHEMA
=
PLATFORM_SCHEMA
.
extend
({
vol
.
Required
(
CONF_ACCESS_TOKEN
):
cv
.
string
})
ICON
=
'
mdi:currency-usd
'
SCAN_INTERVAL
=
timedelta
(
minutes
=
1
)
@asyncio.coroutine
def
async_setup_platform
(
hass
,
config
,
async_add_devices
,
discovery_info
=
None
):
"""
Set up the Tibber sensor.
"""
import
Tibber
tibber
=
Tibber
.
Tibber
(
config
[
CONF_ACCESS_TOKEN
],
websession
=
async_get_clientsession
(
hass
))
yield
from
tibber
.
update_info
()
dev
=
[]
for
home
in
tibber
.
get_homes
():
yield
from
home
.
update_info
()
dev
.
append
(
TibberSensor
(
home
))
async_add_devices
(
dev
)
class
TibberSensor
(
Entity
):
"""
Representation of an Tibber sensor.
"""
def
__init__
(
self
,
tibber_home
):
"""
Initialize the sensor.
"""
self
.
_tibber_home
=
tibber_home
self
.
_last_updated
=
None
self
.
_state
=
None
self
.
_device_state_attributes
=
None
self
.
_unit_of_measurement
=
None
self
.
_name
=
'
Electricity price {}
'
.
format
(
self
.
_tibber_home
.
address1
)
@asyncio.coroutine
def
async_update
(
self
):
"""
Get the latest data and updates the states.
"""
if
self
.
_tibber_home
.
current_price_total
and
self
.
_last_updated
and
\
dt_util
.
as_utc
(
dt_util
.
parse_datetime
(
self
.
_last_updated
)).
hour
\
==
dt_util
.
utcnow
().
hour
:
return
yield
from
self
.
_tibber_home
.
update_current_price_info
()
self
.
_state
=
self
.
_tibber_home
.
current_price_total
self
.
_last_updated
=
self
.
_tibber_home
.
current_price_info
.
\
get
(
'
startsAt
'
)
self
.
_device_state_attributes
=
self
.
_tibber_home
.
current_price_info
self
.
_unit_of_measurement
=
self
.
_tibber_home
.
price_unit
@property
def
device_state_attributes
(
self
):
"""
Return the state attributes.
"""
return
self
.
_device_state_attributes
@property
def
name
(
self
):
"""
Return the name of the sensor.
"""
return
self
.
_name
@property
def
state
(
self
):
"""
Return the state of the device.
"""
return
self
.
_state
@property
def
icon
(
self
):
"""
Return the icon to use in the frontend.
"""
return
ICON
@property
def
unit_of_measurement
(
self
):
"""
Return the unit of measurement of this entity.
"""
return
self
.
_unit_of_measurement
This diff is collapsed.
Click to expand it.
requirements_all.txt
+
3
−
0
View file @
4314dc25
...
...
@@ -552,6 +552,9 @@ pyHS100==0.2.4.2
# homeassistant.components.rfxtrx
pyRFXtrx==0.20.1
# homeassistant.components.sensor.tibber
pyTibber==0.1.1
# homeassistant.components.switch.dlink
pyW215==0.6.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