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

Add flume support #27235

Merged
merged 30 commits into from Nov 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
08bee5c
Add Flume Sensor
ChrisMandich Oct 4, 2019
91112ad
Add support for choosing timezone
ChrisMandich Oct 5, 2019
879dee7
Add Flume to coveragerc and CODEOWNERS
ChrisMandich Oct 5, 2019
1be0d97
Revert "Add Flume to coveragerc and CODEOWNERS"
ChrisMandich Oct 5, 2019
dcecccd
Update manifest.json
ChrisMandich Oct 5, 2019
ed52005
Update manifest.json
ChrisMandich Oct 5, 2019
a30f1ad
Update sensor.py
ChrisMandich Oct 6, 2019
4b0a708
Update Manifest, CODEOWNERS, and manifest.json
ChrisMandich Oct 6, 2019
3d15d35
Update sensor.py
ChrisMandich Oct 7, 2019
c5a25f8
Implemented suggested changes from @Quentame
ChrisMandich Oct 8, 2019
1ee004f
Update sensor.py
ChrisMandich Oct 9, 2019
a524efb
Address pylint errors
ChrisMandich Oct 12, 2019
4f5dfad
Update sensor.py
ChrisMandich Oct 12, 2019
4863008
Address Pylint errors
ChrisMandich Oct 12, 2019
7aa8eec
Update sensor.py
ChrisMandich Oct 13, 2019
b7367f6
Update sensor.py
ChrisMandich Oct 13, 2019
a65d1e4
Update Flume Sensory.py
ChrisMandich Oct 16, 2019
01f3c70
Update sensor.py to support latest pyflume package
ChrisMandich Oct 16, 2019
e3e749e
Update manifest
ChrisMandich Oct 16, 2019
aca83ae
Update manifest.json
ChrisMandich Oct 18, 2019
9671426
Update sensor.py
ChrisMandich Oct 18, 2019
a7238b4
Update requirements_all.txt
ChrisMandich Oct 18, 2019
7617003
Update sensor.py
ChrisMandich Oct 18, 2019
f81c928
Update sensor.py
ChrisMandich Oct 18, 2019
cf88de3
Update sensor.py
ChrisMandich Oct 26, 2019
8600d5e
Update sensor.py
ChrisMandich Oct 28, 2019
a1c0826
Update pyflume version
ChrisMandich Oct 29, 2019
35b2333
Update imports with isort
ChrisMandich Oct 29, 2019
570b25e
Add line break between standard library and thirdparty imports.
ChrisMandich Oct 30, 2019
b511d42
Remove throttle from sensor.py
ChrisMandich Oct 30, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .coveragerc
Expand Up @@ -216,6 +216,7 @@ omit =
homeassistant/components/flexit/climate.py
homeassistant/components/flic/binary_sensor.py
homeassistant/components/flock/notify.py
homeassistant/components/flume/*
homeassistant/components/flunearyou/sensor.py
homeassistant/components/flux_led/light.py
homeassistant/components/folder/sensor.py
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Expand Up @@ -95,6 +95,7 @@ homeassistant/components/filter/* @dgomes
homeassistant/components/fitbit/* @robbiet480
homeassistant/components/fixer/* @fabaff
homeassistant/components/flock/* @fabaff
homeassistant/components/flume/* @ChrisMandich
homeassistant/components/flunearyou/* @bachya
homeassistant/components/fortigate/* @kifeo
homeassistant/components/fortios/* @kimfrellsen
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/flume/__init__.py
@@ -0,0 +1 @@
"""The Flume component."""
11 changes: 11 additions & 0 deletions homeassistant/components/flume/manifest.json
@@ -0,0 +1,11 @@
{
"domain": "flume",
"name": "Flume",
"documentation": "https://www.home-assistant.io/integrations/flume/",
"requirements": [
"pyflume==0.2.1"
],
"dependencies": [],
"codeowners": ["@ChrisMandich"]
}

90 changes: 90 additions & 0 deletions homeassistant/components/flume/sensor.py
@@ -0,0 +1,90 @@
"""Sensor for displaying the number of result from Flume."""
from datetime import timedelta
import logging

from pyflume import FlumeData, FlumeDeviceList
ChrisMandich marked this conversation as resolved.
Show resolved Hide resolved
import voluptuous as vol

ChrisMandich marked this conversation as resolved.
Show resolved Hide resolved
from homeassistant.components.sensor import PLATFORM_SCHEMA
ChrisMandich marked this conversation as resolved.
Show resolved Hide resolved
from homeassistant.const import CONF_NAME, CONF_PASSWORD, CONF_USERNAME
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity

LOGGER = logging.getLogger(__name__)

DEFAULT_NAME = "Flume Sensor"

CONF_CLIENT_ID = "client_id"
CONF_CLIENT_SECRET = "client_secret"
FLUME_TYPE_SENSOR = 2

SCAN_INTERVAL = timedelta(minutes=1)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Required(CONF_CLIENT_ID): cv.string,
vol.Required(CONF_CLIENT_SECRET): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
}
)


def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Flume sensor."""
username = config[CONF_USERNAME]
password = config[CONF_PASSWORD]
client_id = config[CONF_CLIENT_ID]
client_secret = config[CONF_CLIENT_SECRET]
time_zone = str(hass.config.time_zone)
name = config[CONF_NAME]
flume_entity_list = []

flume_devices = FlumeDeviceList(username, password, client_id, client_secret)

for device in flume_devices.device_list:
if device["type"] == FLUME_TYPE_SENSOR:
flume = FlumeData(
username,
password,
client_id,
client_secret,
device["id"],
time_zone,
SCAN_INTERVAL,
)
flume_entity_list.append(FlumeSensor(flume, f"{name} {device['id']}"))

if flume_entity_list:
add_entities(flume_entity_list, True)


class FlumeSensor(Entity):
"""Representation of the Flume sensor."""

def __init__(self, flume, name):
"""Initialize the Flume sensor."""
self.flume = flume
self._name = name
self._state = None

@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 the value is expressed in."""
return "gal"

def update(self):
"""Get the latest data and updates the states."""
self.flume.update()
self._state = self.flume.value
3 changes: 3 additions & 0 deletions requirements_all.txt
Expand Up @@ -1185,6 +1185,9 @@ pyflexit==0.3
# homeassistant.components.flic
pyflic-homeassistant==0.4.dev0

# homeassistant.components.flume
pyflume==0.2.1

# homeassistant.components.flunearyou
pyflunearyou==1.0.3

Expand Down