Skip to content
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

Suez water #23844

Merged
merged 38 commits into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ca3df87
Add suez water sensor
May 10, 2019
6060924
flake8 test
May 10, 2019
10d465c
pylint test
May 10, 2019
ae64f79
edition to fix flake8 and pylint issues
May 10, 2019
5e7542c
edition to be okay with the musts
May 10, 2019
900a0ba
Added a blank line to __init.py__ for flake8
May 10, 2019
e46b070
added blank line for flake8
May 13, 2019
f43247b
Merge branch 'suezWater' of https://github.com/ooii/home-assistant in…
May 13, 2019
764d94b
changer scan interval from 10 to 720 minutes
May 13, 2019
3fedfec
use of pysuez
Jun 3, 2019
ee24baa
bug fix and isort
Jun 3, 2019
74d799e
use of pysuez
Jun 4, 2019
a80391e
fixed flake8 and pylint errors
Jun 4, 2019
61a9695
update requirements_all.txt
Jun 4, 2019
0f20749
added a method to test login/password befire adding device
Jun 4, 2019
6390bff
flake8 edition
Jun 4, 2019
0386e2d
update requirements_all.txt
Jun 4, 2019
a9031a4
add of .coveragerc file with untested files
Jun 5, 2019
8573e43
update of .coveragerc
Jun 5, 2019
b944137
Update homeassistant/components/suez_water/__init__.py
ooii Jun 7, 2019
3394a21
Update homeassistant/components/suez_water/sensor.py
ooii Jun 7, 2019
32c68b9
Update homeassistant/components/suez_water/sensor.py
ooii Jun 7, 2019
5f4189d
Update homeassistant/components/suez_water/sensor.py
ooii Jun 7, 2019
a90df5c
Update homeassistant/components/suez_water/sensor.py
ooii Jun 7, 2019
65ff9c7
Update homeassistant/components/suez_water/sensor.py
ooii Jun 7, 2019
7878697
bug fix in check credentials
Jun 7, 2019
ebd5ac1
flake8 and pylint fixes
Jun 7, 2019
a781c95
fix codeowner
Jun 8, 2019
37232e3
update requirements_all.txt
Jun 8, 2019
8db21b2
Merge branch 'dev' into suezWater
ooii Jun 11, 2019
d636f79
Merge branch 'dev' into suezWater
ooii Jun 25, 2019
993471f
Sorted suez_water line
ooii Jul 3, 2019
2db8648
edition to answer comments from @MartinHjelmare on #23844
Jul 3, 2019
50e74df
Merge branch 'suezWater' of https://github.com/ooii/home-assistant in…
Jul 3, 2019
af38c6e
Attribute keys formatting to lowercase snakecase, name and icon const…
Jul 3, 2019
445e69d
pylint edition
Jul 4, 2019
d3a2263
correction wrong keys in client attributes
Jul 4, 2019
1726da1
remove of unnedeed return and move add_entities
Jul 23, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ omit =
homeassistant/components/stiebel_eltron/*
homeassistant/components/streamlabswater/*
homeassistant/components/stride/notify.py
homeassistant/components/suez_water/*
homeassistant/components/supervisord/sensor.py
homeassistant/components/swiss_hydrological_data/sensor.py
homeassistant/components/swiss_public_transport/sensor.py
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ homeassistant/components/sql/* @dgomes
homeassistant/components/statistics/* @fabaff
homeassistant/components/stiebel_eltron/* @fucm
homeassistant/components/stream/* @hunterjm
homeassistant/components/suez_water/* @ooii
homeassistant/components/sun/* @Swamp-Ig
homeassistant/components/supla/* @mwegrzynek
homeassistant/components/swiss_hydrological_data/* @fabaff
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/suez_water/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""France Suez Water integration."""
8 changes: 8 additions & 0 deletions homeassistant/components/suez_water/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"domain": "suez_water",
"name": "Suez Water Consumption Sensor",
"documentation": "https://www.home-assistant.io/components/suez_water",
"dependencies": [],
"codeowners": ["@ooii"],
"requirements": ["pysuez==0.1.17"]
}
134 changes: 134 additions & 0 deletions homeassistant/components/suez_water/sensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
"""Sensor for Suez Water Consumption data."""
from datetime import timedelta
import logging

import voluptuous as vol

from pysuez.client import PySuezError
from pysuez import SuezClient

from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, VOLUME_LITERS
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity

_LOGGER = logging.getLogger(__name__)
CONF_COUNTER_ID = 'counter_id'

SCAN_INTERVAL = timedelta(hours=12)

COMPONENT_ICON = 'mdi:water-pump'
COMPONENT_NAME = "Suez Water Client"

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Required(CONF_COUNTER_ID): cv.string,
})


def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the sensor platform."""
username = config[CONF_USERNAME]
password = config[CONF_PASSWORD]
counter_id = config[CONF_COUNTER_ID]
try:
client = SuezClient(
username, password, counter_id)

if not client.check_credentials():
_LOGGER.warning("Wrong username and/or password")
else:
add_entities([SuezSensor(client)], True)

except PySuezError:
_LOGGER.warning("Unable to create Suez Client")
return


class SuezSensor(Entity):
"""Representation of a Sensor."""

def __init__(self, client):
"""Initialize the data object."""
self._name = COMPONENT_NAME
self._attributes = {}
self._state = None
self._available = None
self._icon = COMPONENT_ICON
self.client = client
self.success = False

@property
def name(self):
"""Return the name of the sensor."""
return self._name

@property
def state(self):
"""Return the state of the sensor."""
return self._state

@property
def unit_of_measurement(self):
"""Return the unit of measurement."""
return VOLUME_LITERS

@property
def device_state_attributes(self):
"""Return the state attributes."""
return self._attributes

@property
def icon(self):
"""Return the icon of the sensor."""
return self._icon

def _fetch_data(self):
"""Fetch latest data from Suez."""
try:
self.client.update()
# _state holds the volume of consumed water during previous day
self._state = self.client.state
self.success = True
self._available = True
self._attributes[
'attribution'] = self.client.attributes[
'attribution']
self._attributes['thisMonthConsumption'] = {}
for item in self.client.attributes['thisMonthConsumption']:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the items?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Daily current month consumption.
I can't know the number of items in advance.

self._attributes['thisMonthConsumption'][
item] = self.client.attributes[
'thisMonthConsumption'][item]
self._attributes['previousMonthConsumption'] = {}
for item in self.client.attributes['previousMonthConsumption']:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the items?

Copy link
Contributor Author

@ooii ooii Jul 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Daily previous month consumption.
I can't know the number of items in advance.

self._attributes['previousMonthConsumption'][
item] = self.client.attributes[
'previousMonthConsumption'][item]
self._attributes[
'highestMonthlyConsumption'] = self.client.attributes[
'highestMonthlyConsumption']
self._attributes[
'lastYearOverAll'] = self.client.attributes[
'lastYearOverAll']
self._attributes[
'thisYearOverAll'] = self.client.attributes[
'thisYearOverAll']
self._attributes['history'] = {}
for item in self.client.attributes['history']:
self._attributes[
'history'][item] = self.client.attributes[
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the items?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latest months consumption.
I can't know the number of items in advance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is each item key the name of the month and the item value is the month consumption in liters?

Please describe the item in more detail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, did not see this question.
history will looks like that:

{ "Février 2019": 10109, "Mars 2019": 7553, "Avril 2019": 9003, "Mai 2019": 8844, "Juin 2019": 10472, "Juillet 2019": 4168 }

It seems that history contains last 6 months consumption.

'history'][item]

except PySuezError:
self.success = False
self._available = False
_LOGGER.warning("Unable to fetch data")
return

def update(self):
"""Return the latest collected data from Linky."""
self._fetch_data()
_LOGGER.debug(
"Suez data state is: %s, and the success is %s",
self._state, self.success)
15 changes: 15 additions & 0 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ datadog==0.15.0
# homeassistant.components.metoffice
datapoint==0.4.3

# homeassistant.components.suez_water
datetime==4.3

# homeassistant.components.decora
# decora==0.6

Expand Down Expand Up @@ -1375,6 +1378,9 @@ pystiebeleltron==0.0.1.dev2
# homeassistant.components.stride
pystride==0.1.7

# homeassistant.components.suez_water
pysuez==0.1.17

# homeassistant.components.supla
pysupla==0.0.3

Expand Down Expand Up @@ -1586,6 +1592,12 @@ recollect-waste==1.0.1
# homeassistant.components.rainmachine
regenmaschine==1.5.1

# homeassistant.components.suez_water
regex==2019.4.14

# homeassistant.components.suez_water
requests==2.21.0

# homeassistant.components.python_script
restrictedpython==4.0b8

Expand Down Expand Up @@ -1837,6 +1849,9 @@ vigilancemeteo==3.0.0
# homeassistant.components.volkszaehler
volkszaehler==0.1.2

# homeassistant.components.suez_water
voluptuous==0.11.5

# homeassistant.components.volvooncall
volvooncall==0.8.7

Expand Down