diff --git a/.coveragerc b/.coveragerc index a241c9ab79c..20be7adbd94 100644 --- a/.coveragerc +++ b/.coveragerc @@ -229,6 +229,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 diff --git a/CODEOWNERS b/CODEOWNERS index 6b4b3e6a2f2..0aca3b9d6fb 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -101,6 +101,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 diff --git a/homeassistant/components/flume/__init__.py b/homeassistant/components/flume/__init__.py new file mode 100644 index 00000000000..ab626e1f156 --- /dev/null +++ b/homeassistant/components/flume/__init__.py @@ -0,0 +1 @@ +"""The Flume component.""" diff --git a/homeassistant/components/flume/manifest.json b/homeassistant/components/flume/manifest.json new file mode 100644 index 00000000000..800751e80ef --- /dev/null +++ b/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"] + } + \ No newline at end of file diff --git a/homeassistant/components/flume/sensor.py b/homeassistant/components/flume/sensor.py new file mode 100644 index 00000000000..5fee408e0dc --- /dev/null +++ b/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 +import voluptuous as vol + +from homeassistant.components.sensor import PLATFORM_SCHEMA +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 diff --git a/requirements_all.txt b/requirements_all.txt index 7d7852add97..ba69df2f28a 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1225,6 +1225,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