core/homeassistant/components/flume/sensor.py

166 lines
5.0 KiB
Python
Raw Normal View History

Add flume support (#27235) * Add Flume Sensor Add support for Flume API and sensor * Add support for choosing timezone Timezone is now a required option in configuration.yaml * Add Flume to coveragerc and CODEOWNERS Add flume to be ommited from testing. Add @ChrisMandich as Flume Code owner * Revert "Add Flume to coveragerc and CODEOWNERS" This reverts commit 0b27437a3b13f024332c6498b3bb0d554482e49b. * Update manifest.json Added Documentation URL for Flume to HASS.IO * Update manifest.json Added missing Newline at EOF. * Update sensor.py Update sensor to not required Device ID for configuration. Now loops through all available Type 2 devices and adds them as an entity. * Update Manifest, CODEOWNERS, and manifest.json Resolved errors related to code owners and requirements. Using hassfest and gen_requirements_all * Update sensor.py Implemented recommendations from @Quentame. Including time zone from Home Assistant, Updated variable names, and Consolidated duplicate functions. * Implemented suggested changes from @Quentame This includes: components name, using f-strings instead of concat, snake_case for variables, constants for the addition of future device types, clearer errors, and removed variables no longer in use. * Update sensor.py Restored unit_of_measurement. Updated return to "gal". * Address pylint errors * Update sensor.py Include protected attributes in setup_platform. * Address Pylint errors homeassistant/components/flume/sensor.py:63:11: W0703: Catching too general exception Exception (broad-except) homeassistant/components/flume/sensor.py:133:8: R1720: Unnecessary "else" after "raise" (no-else-raise) homeassistant/components/flume/sensor.py:162:8: R1705: Unnecessary "else" after "return" (no-else-return) homeassistant/components/flume/sensor.py:236:8: R1720: Unnecessary "else" after "raise" (no-else-raise) * Update sensor.py I'm okay with the broad exception clause. homeassistant/components/flume/sensor.py:65:11: W0703: Catching too general exception Exception (broad-except) * Update sensor.py Add more specific exceptions for Try/Except. * Update Flume Sensory.py add requirements, exclude from tests, us pyflume pypi package. * Update sensor.py to support latest pyflume package * Update manifest provide better flow of manifest and easier readibility. * Update manifest.json Reccomended by @balloob as it is already a core requirement * Update sensor.py Add proposed changes from @balloob * Update requirements_all.txt pytz is a core dependency, removing flume's requirement for it. * Update sensor.py Added @MartinHjelmare recommended changes. * Update sensor.py Resolving PyLint error * Update sensor.py Remove `KeyError`. Add length check for flume entity list before adding. * Update sensor.py * Update pyflume version * Update imports with isort * Add line break between standard library and thirdparty imports. * Remove throttle from sensor.py
2019-11-23 08:55:46 +00:00
"""Sensor for displaying the number of result from Flume."""
from datetime import timedelta
import logging
from numbers import Number
Add flume support (#27235) * Add Flume Sensor Add support for Flume API and sensor * Add support for choosing timezone Timezone is now a required option in configuration.yaml * Add Flume to coveragerc and CODEOWNERS Add flume to be ommited from testing. Add @ChrisMandich as Flume Code owner * Revert "Add Flume to coveragerc and CODEOWNERS" This reverts commit 0b27437a3b13f024332c6498b3bb0d554482e49b. * Update manifest.json Added Documentation URL for Flume to HASS.IO * Update manifest.json Added missing Newline at EOF. * Update sensor.py Update sensor to not required Device ID for configuration. Now loops through all available Type 2 devices and adds them as an entity. * Update Manifest, CODEOWNERS, and manifest.json Resolved errors related to code owners and requirements. Using hassfest and gen_requirements_all * Update sensor.py Implemented recommendations from @Quentame. Including time zone from Home Assistant, Updated variable names, and Consolidated duplicate functions. * Implemented suggested changes from @Quentame This includes: components name, using f-strings instead of concat, snake_case for variables, constants for the addition of future device types, clearer errors, and removed variables no longer in use. * Update sensor.py Restored unit_of_measurement. Updated return to "gal". * Address pylint errors * Update sensor.py Include protected attributes in setup_platform. * Address Pylint errors homeassistant/components/flume/sensor.py:63:11: W0703: Catching too general exception Exception (broad-except) homeassistant/components/flume/sensor.py:133:8: R1720: Unnecessary "else" after "raise" (no-else-raise) homeassistant/components/flume/sensor.py:162:8: R1705: Unnecessary "else" after "return" (no-else-return) homeassistant/components/flume/sensor.py:236:8: R1720: Unnecessary "else" after "raise" (no-else-raise) * Update sensor.py I'm okay with the broad exception clause. homeassistant/components/flume/sensor.py:65:11: W0703: Catching too general exception Exception (broad-except) * Update sensor.py Add more specific exceptions for Try/Except. * Update Flume Sensory.py add requirements, exclude from tests, us pyflume pypi package. * Update sensor.py to support latest pyflume package * Update manifest provide better flow of manifest and easier readibility. * Update manifest.json Reccomended by @balloob as it is already a core requirement * Update sensor.py Add proposed changes from @balloob * Update requirements_all.txt pytz is a core dependency, removing flume's requirement for it. * Update sensor.py Added @MartinHjelmare recommended changes. * Update sensor.py Resolving PyLint error * Update sensor.py Remove `KeyError`. Add length check for flume entity list before adding. * Update sensor.py * Update pyflume version * Update imports with isort * Add line break between standard library and thirdparty imports. * Remove throttle from sensor.py
2019-11-23 08:55:46 +00:00
from pyflume import FlumeData
Add flume support (#27235) * Add Flume Sensor Add support for Flume API and sensor * Add support for choosing timezone Timezone is now a required option in configuration.yaml * Add Flume to coveragerc and CODEOWNERS Add flume to be ommited from testing. Add @ChrisMandich as Flume Code owner * Revert "Add Flume to coveragerc and CODEOWNERS" This reverts commit 0b27437a3b13f024332c6498b3bb0d554482e49b. * Update manifest.json Added Documentation URL for Flume to HASS.IO * Update manifest.json Added missing Newline at EOF. * Update sensor.py Update sensor to not required Device ID for configuration. Now loops through all available Type 2 devices and adds them as an entity. * Update Manifest, CODEOWNERS, and manifest.json Resolved errors related to code owners and requirements. Using hassfest and gen_requirements_all * Update sensor.py Implemented recommendations from @Quentame. Including time zone from Home Assistant, Updated variable names, and Consolidated duplicate functions. * Implemented suggested changes from @Quentame This includes: components name, using f-strings instead of concat, snake_case for variables, constants for the addition of future device types, clearer errors, and removed variables no longer in use. * Update sensor.py Restored unit_of_measurement. Updated return to "gal". * Address pylint errors * Update sensor.py Include protected attributes in setup_platform. * Address Pylint errors homeassistant/components/flume/sensor.py:63:11: W0703: Catching too general exception Exception (broad-except) homeassistant/components/flume/sensor.py:133:8: R1720: Unnecessary "else" after "raise" (no-else-raise) homeassistant/components/flume/sensor.py:162:8: R1705: Unnecessary "else" after "return" (no-else-return) homeassistant/components/flume/sensor.py:236:8: R1720: Unnecessary "else" after "raise" (no-else-raise) * Update sensor.py I'm okay with the broad exception clause. homeassistant/components/flume/sensor.py:65:11: W0703: Catching too general exception Exception (broad-except) * Update sensor.py Add more specific exceptions for Try/Except. * Update Flume Sensory.py add requirements, exclude from tests, us pyflume pypi package. * Update sensor.py to support latest pyflume package * Update manifest provide better flow of manifest and easier readibility. * Update manifest.json Reccomended by @balloob as it is already a core requirement * Update sensor.py Add proposed changes from @balloob * Update requirements_all.txt pytz is a core dependency, removing flume's requirement for it. * Update sensor.py Added @MartinHjelmare recommended changes. * Update sensor.py Resolving PyLint error * Update sensor.py Remove `KeyError`. Add length check for flume entity list before adding. * Update sensor.py * Update pyflume version * Update imports with isort * Add line break between standard library and thirdparty imports. * Remove throttle from sensor.py
2019-11-23 08:55:46 +00:00
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_NAME
from homeassistant.core import HomeAssistant
2021-10-23 10:01:21 +00:00
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
UpdateFailed,
)
from .const import (
DEFAULT_NAME,
DOMAIN,
FLUME_AUTH,
FLUME_DEVICES,
FLUME_HTTP_SESSION,
FLUME_QUERIES_SENSOR,
FLUME_TYPE_SENSOR,
KEY_DEVICE_ID,
KEY_DEVICE_LOCATION,
KEY_DEVICE_LOCATION_NAME,
KEY_DEVICE_LOCATION_TIMEZONE,
KEY_DEVICE_TYPE,
)
Add flume support (#27235) * Add Flume Sensor Add support for Flume API and sensor * Add support for choosing timezone Timezone is now a required option in configuration.yaml * Add Flume to coveragerc and CODEOWNERS Add flume to be ommited from testing. Add @ChrisMandich as Flume Code owner * Revert "Add Flume to coveragerc and CODEOWNERS" This reverts commit 0b27437a3b13f024332c6498b3bb0d554482e49b. * Update manifest.json Added Documentation URL for Flume to HASS.IO * Update manifest.json Added missing Newline at EOF. * Update sensor.py Update sensor to not required Device ID for configuration. Now loops through all available Type 2 devices and adds them as an entity. * Update Manifest, CODEOWNERS, and manifest.json Resolved errors related to code owners and requirements. Using hassfest and gen_requirements_all * Update sensor.py Implemented recommendations from @Quentame. Including time zone from Home Assistant, Updated variable names, and Consolidated duplicate functions. * Implemented suggested changes from @Quentame This includes: components name, using f-strings instead of concat, snake_case for variables, constants for the addition of future device types, clearer errors, and removed variables no longer in use. * Update sensor.py Restored unit_of_measurement. Updated return to "gal". * Address pylint errors * Update sensor.py Include protected attributes in setup_platform. * Address Pylint errors homeassistant/components/flume/sensor.py:63:11: W0703: Catching too general exception Exception (broad-except) homeassistant/components/flume/sensor.py:133:8: R1720: Unnecessary "else" after "raise" (no-else-raise) homeassistant/components/flume/sensor.py:162:8: R1705: Unnecessary "else" after "return" (no-else-return) homeassistant/components/flume/sensor.py:236:8: R1720: Unnecessary "else" after "raise" (no-else-raise) * Update sensor.py I'm okay with the broad exception clause. homeassistant/components/flume/sensor.py:65:11: W0703: Catching too general exception Exception (broad-except) * Update sensor.py Add more specific exceptions for Try/Except. * Update Flume Sensory.py add requirements, exclude from tests, us pyflume pypi package. * Update sensor.py to support latest pyflume package * Update manifest provide better flow of manifest and easier readibility. * Update manifest.json Reccomended by @balloob as it is already a core requirement * Update sensor.py Add proposed changes from @balloob * Update requirements_all.txt pytz is a core dependency, removing flume's requirement for it. * Update sensor.py Added @MartinHjelmare recommended changes. * Update sensor.py Resolving PyLint error * Update sensor.py Remove `KeyError`. Add length check for flume entity list before adding. * Update sensor.py * Update pyflume version * Update imports with isort * Add line break between standard library and thirdparty imports. * Remove throttle from sensor.py
2019-11-23 08:55:46 +00:00
_LOGGER = logging.getLogger(__name__)
Add flume support (#27235) * Add Flume Sensor Add support for Flume API and sensor * Add support for choosing timezone Timezone is now a required option in configuration.yaml * Add Flume to coveragerc and CODEOWNERS Add flume to be ommited from testing. Add @ChrisMandich as Flume Code owner * Revert "Add Flume to coveragerc and CODEOWNERS" This reverts commit 0b27437a3b13f024332c6498b3bb0d554482e49b. * Update manifest.json Added Documentation URL for Flume to HASS.IO * Update manifest.json Added missing Newline at EOF. * Update sensor.py Update sensor to not required Device ID for configuration. Now loops through all available Type 2 devices and adds them as an entity. * Update Manifest, CODEOWNERS, and manifest.json Resolved errors related to code owners and requirements. Using hassfest and gen_requirements_all * Update sensor.py Implemented recommendations from @Quentame. Including time zone from Home Assistant, Updated variable names, and Consolidated duplicate functions. * Implemented suggested changes from @Quentame This includes: components name, using f-strings instead of concat, snake_case for variables, constants for the addition of future device types, clearer errors, and removed variables no longer in use. * Update sensor.py Restored unit_of_measurement. Updated return to "gal". * Address pylint errors * Update sensor.py Include protected attributes in setup_platform. * Address Pylint errors homeassistant/components/flume/sensor.py:63:11: W0703: Catching too general exception Exception (broad-except) homeassistant/components/flume/sensor.py:133:8: R1720: Unnecessary "else" after "raise" (no-else-raise) homeassistant/components/flume/sensor.py:162:8: R1705: Unnecessary "else" after "return" (no-else-return) homeassistant/components/flume/sensor.py:236:8: R1720: Unnecessary "else" after "raise" (no-else-raise) * Update sensor.py I'm okay with the broad exception clause. homeassistant/components/flume/sensor.py:65:11: W0703: Catching too general exception Exception (broad-except) * Update sensor.py Add more specific exceptions for Try/Except. * Update Flume Sensory.py add requirements, exclude from tests, us pyflume pypi package. * Update sensor.py to support latest pyflume package * Update manifest provide better flow of manifest and easier readibility. * Update manifest.json Reccomended by @balloob as it is already a core requirement * Update sensor.py Add proposed changes from @balloob * Update requirements_all.txt pytz is a core dependency, removing flume's requirement for it. * Update sensor.py Added @MartinHjelmare recommended changes. * Update sensor.py Resolving PyLint error * Update sensor.py Remove `KeyError`. Add length check for flume entity list before adding. * Update sensor.py * Update pyflume version * Update imports with isort * Add line break between standard library and thirdparty imports. * Remove throttle from sensor.py
2019-11-23 08:55:46 +00:00
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=15)
Add flume support (#27235) * Add Flume Sensor Add support for Flume API and sensor * Add support for choosing timezone Timezone is now a required option in configuration.yaml * Add Flume to coveragerc and CODEOWNERS Add flume to be ommited from testing. Add @ChrisMandich as Flume Code owner * Revert "Add Flume to coveragerc and CODEOWNERS" This reverts commit 0b27437a3b13f024332c6498b3bb0d554482e49b. * Update manifest.json Added Documentation URL for Flume to HASS.IO * Update manifest.json Added missing Newline at EOF. * Update sensor.py Update sensor to not required Device ID for configuration. Now loops through all available Type 2 devices and adds them as an entity. * Update Manifest, CODEOWNERS, and manifest.json Resolved errors related to code owners and requirements. Using hassfest and gen_requirements_all * Update sensor.py Implemented recommendations from @Quentame. Including time zone from Home Assistant, Updated variable names, and Consolidated duplicate functions. * Implemented suggested changes from @Quentame This includes: components name, using f-strings instead of concat, snake_case for variables, constants for the addition of future device types, clearer errors, and removed variables no longer in use. * Update sensor.py Restored unit_of_measurement. Updated return to "gal". * Address pylint errors * Update sensor.py Include protected attributes in setup_platform. * Address Pylint errors homeassistant/components/flume/sensor.py:63:11: W0703: Catching too general exception Exception (broad-except) homeassistant/components/flume/sensor.py:133:8: R1720: Unnecessary "else" after "raise" (no-else-raise) homeassistant/components/flume/sensor.py:162:8: R1705: Unnecessary "else" after "return" (no-else-return) homeassistant/components/flume/sensor.py:236:8: R1720: Unnecessary "else" after "raise" (no-else-raise) * Update sensor.py I'm okay with the broad exception clause. homeassistant/components/flume/sensor.py:65:11: W0703: Catching too general exception Exception (broad-except) * Update sensor.py Add more specific exceptions for Try/Except. * Update Flume Sensory.py add requirements, exclude from tests, us pyflume pypi package. * Update sensor.py to support latest pyflume package * Update manifest provide better flow of manifest and easier readibility. * Update manifest.json Reccomended by @balloob as it is already a core requirement * Update sensor.py Add proposed changes from @balloob * Update requirements_all.txt pytz is a core dependency, removing flume's requirement for it. * Update sensor.py Added @MartinHjelmare recommended changes. * Update sensor.py Resolving PyLint error * Update sensor.py Remove `KeyError`. Add length check for flume entity list before adding. * Update sensor.py * Update pyflume version * Update imports with isort * Add line break between standard library and thirdparty imports. * Remove throttle from sensor.py
2019-11-23 08:55:46 +00:00
SCAN_INTERVAL = timedelta(minutes=1)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
Add flume support (#27235) * Add Flume Sensor Add support for Flume API and sensor * Add support for choosing timezone Timezone is now a required option in configuration.yaml * Add Flume to coveragerc and CODEOWNERS Add flume to be ommited from testing. Add @ChrisMandich as Flume Code owner * Revert "Add Flume to coveragerc and CODEOWNERS" This reverts commit 0b27437a3b13f024332c6498b3bb0d554482e49b. * Update manifest.json Added Documentation URL for Flume to HASS.IO * Update manifest.json Added missing Newline at EOF. * Update sensor.py Update sensor to not required Device ID for configuration. Now loops through all available Type 2 devices and adds them as an entity. * Update Manifest, CODEOWNERS, and manifest.json Resolved errors related to code owners and requirements. Using hassfest and gen_requirements_all * Update sensor.py Implemented recommendations from @Quentame. Including time zone from Home Assistant, Updated variable names, and Consolidated duplicate functions. * Implemented suggested changes from @Quentame This includes: components name, using f-strings instead of concat, snake_case for variables, constants for the addition of future device types, clearer errors, and removed variables no longer in use. * Update sensor.py Restored unit_of_measurement. Updated return to "gal". * Address pylint errors * Update sensor.py Include protected attributes in setup_platform. * Address Pylint errors homeassistant/components/flume/sensor.py:63:11: W0703: Catching too general exception Exception (broad-except) homeassistant/components/flume/sensor.py:133:8: R1720: Unnecessary "else" after "raise" (no-else-raise) homeassistant/components/flume/sensor.py:162:8: R1705: Unnecessary "else" after "return" (no-else-return) homeassistant/components/flume/sensor.py:236:8: R1720: Unnecessary "else" after "raise" (no-else-raise) * Update sensor.py I'm okay with the broad exception clause. homeassistant/components/flume/sensor.py:65:11: W0703: Catching too general exception Exception (broad-except) * Update sensor.py Add more specific exceptions for Try/Except. * Update Flume Sensory.py add requirements, exclude from tests, us pyflume pypi package. * Update sensor.py to support latest pyflume package * Update manifest provide better flow of manifest and easier readibility. * Update manifest.json Reccomended by @balloob as it is already a core requirement * Update sensor.py Add proposed changes from @balloob * Update requirements_all.txt pytz is a core dependency, removing flume's requirement for it. * Update sensor.py Added @MartinHjelmare recommended changes. * Update sensor.py Resolving PyLint error * Update sensor.py Remove `KeyError`. Add length check for flume entity list before adding. * Update sensor.py * Update pyflume version * Update imports with isort * Add line break between standard library and thirdparty imports. * Remove throttle from sensor.py
2019-11-23 08:55:46 +00:00
"""Set up the Flume sensor."""
flume_domain_data = hass.data[DOMAIN][config_entry.entry_id]
flume_auth = flume_domain_data[FLUME_AUTH]
http_session = flume_domain_data[FLUME_HTTP_SESSION]
flume_devices = flume_domain_data[FLUME_DEVICES]
config = config_entry.data
name = config.get(CONF_NAME, DEFAULT_NAME)
Add flume support (#27235) * Add Flume Sensor Add support for Flume API and sensor * Add support for choosing timezone Timezone is now a required option in configuration.yaml * Add Flume to coveragerc and CODEOWNERS Add flume to be ommited from testing. Add @ChrisMandich as Flume Code owner * Revert "Add Flume to coveragerc and CODEOWNERS" This reverts commit 0b27437a3b13f024332c6498b3bb0d554482e49b. * Update manifest.json Added Documentation URL for Flume to HASS.IO * Update manifest.json Added missing Newline at EOF. * Update sensor.py Update sensor to not required Device ID for configuration. Now loops through all available Type 2 devices and adds them as an entity. * Update Manifest, CODEOWNERS, and manifest.json Resolved errors related to code owners and requirements. Using hassfest and gen_requirements_all * Update sensor.py Implemented recommendations from @Quentame. Including time zone from Home Assistant, Updated variable names, and Consolidated duplicate functions. * Implemented suggested changes from @Quentame This includes: components name, using f-strings instead of concat, snake_case for variables, constants for the addition of future device types, clearer errors, and removed variables no longer in use. * Update sensor.py Restored unit_of_measurement. Updated return to "gal". * Address pylint errors * Update sensor.py Include protected attributes in setup_platform. * Address Pylint errors homeassistant/components/flume/sensor.py:63:11: W0703: Catching too general exception Exception (broad-except) homeassistant/components/flume/sensor.py:133:8: R1720: Unnecessary "else" after "raise" (no-else-raise) homeassistant/components/flume/sensor.py:162:8: R1705: Unnecessary "else" after "return" (no-else-return) homeassistant/components/flume/sensor.py:236:8: R1720: Unnecessary "else" after "raise" (no-else-raise) * Update sensor.py I'm okay with the broad exception clause. homeassistant/components/flume/sensor.py:65:11: W0703: Catching too general exception Exception (broad-except) * Update sensor.py Add more specific exceptions for Try/Except. * Update Flume Sensory.py add requirements, exclude from tests, us pyflume pypi package. * Update sensor.py to support latest pyflume package * Update manifest provide better flow of manifest and easier readibility. * Update manifest.json Reccomended by @balloob as it is already a core requirement * Update sensor.py Add proposed changes from @balloob * Update requirements_all.txt pytz is a core dependency, removing flume's requirement for it. * Update sensor.py Added @MartinHjelmare recommended changes. * Update sensor.py Resolving PyLint error * Update sensor.py Remove `KeyError`. Add length check for flume entity list before adding. * Update sensor.py * Update pyflume version * Update imports with isort * Add line break between standard library and thirdparty imports. * Remove throttle from sensor.py
2019-11-23 08:55:46 +00:00
flume_entity_list = []
Add flume support (#27235) * Add Flume Sensor Add support for Flume API and sensor * Add support for choosing timezone Timezone is now a required option in configuration.yaml * Add Flume to coveragerc and CODEOWNERS Add flume to be ommited from testing. Add @ChrisMandich as Flume Code owner * Revert "Add Flume to coveragerc and CODEOWNERS" This reverts commit 0b27437a3b13f024332c6498b3bb0d554482e49b. * Update manifest.json Added Documentation URL for Flume to HASS.IO * Update manifest.json Added missing Newline at EOF. * Update sensor.py Update sensor to not required Device ID for configuration. Now loops through all available Type 2 devices and adds them as an entity. * Update Manifest, CODEOWNERS, and manifest.json Resolved errors related to code owners and requirements. Using hassfest and gen_requirements_all * Update sensor.py Implemented recommendations from @Quentame. Including time zone from Home Assistant, Updated variable names, and Consolidated duplicate functions. * Implemented suggested changes from @Quentame This includes: components name, using f-strings instead of concat, snake_case for variables, constants for the addition of future device types, clearer errors, and removed variables no longer in use. * Update sensor.py Restored unit_of_measurement. Updated return to "gal". * Address pylint errors * Update sensor.py Include protected attributes in setup_platform. * Address Pylint errors homeassistant/components/flume/sensor.py:63:11: W0703: Catching too general exception Exception (broad-except) homeassistant/components/flume/sensor.py:133:8: R1720: Unnecessary "else" after "raise" (no-else-raise) homeassistant/components/flume/sensor.py:162:8: R1705: Unnecessary "else" after "return" (no-else-return) homeassistant/components/flume/sensor.py:236:8: R1720: Unnecessary "else" after "raise" (no-else-raise) * Update sensor.py I'm okay with the broad exception clause. homeassistant/components/flume/sensor.py:65:11: W0703: Catching too general exception Exception (broad-except) * Update sensor.py Add more specific exceptions for Try/Except. * Update Flume Sensory.py add requirements, exclude from tests, us pyflume pypi package. * Update sensor.py to support latest pyflume package * Update manifest provide better flow of manifest and easier readibility. * Update manifest.json Reccomended by @balloob as it is already a core requirement * Update sensor.py Add proposed changes from @balloob * Update requirements_all.txt pytz is a core dependency, removing flume's requirement for it. * Update sensor.py Added @MartinHjelmare recommended changes. * Update sensor.py Resolving PyLint error * Update sensor.py Remove `KeyError`. Add length check for flume entity list before adding. * Update sensor.py * Update pyflume version * Update imports with isort * Add line break between standard library and thirdparty imports. * Remove throttle from sensor.py
2019-11-23 08:55:46 +00:00
for device in flume_devices.device_list:
if device[KEY_DEVICE_TYPE] != FLUME_TYPE_SENSOR:
continue
device_id = device[KEY_DEVICE_ID]
device_name = device[KEY_DEVICE_LOCATION][KEY_DEVICE_LOCATION_NAME]
device_timezone = device[KEY_DEVICE_LOCATION][KEY_DEVICE_LOCATION_TIMEZONE]
device_friendly_name = f"{name} {device_name}"
flume_device = FlumeData(
flume_auth,
device_id,
device_timezone,
SCAN_INTERVAL,
update_on_init=False,
http_session=http_session,
)
coordinator = _create_flume_device_coordinator(hass, flume_device)
2021-09-20 16:13:09 +00:00
flume_entity_list.extend(
[
FlumeSensor(
coordinator,
flume_device,
2021-09-20 16:13:09 +00:00
device_friendly_name,
device_id,
2021-09-20 16:13:09 +00:00
description,
)
2021-09-20 16:13:09 +00:00
for description in FLUME_QUERIES_SENSOR
]
)
Add flume support (#27235) * Add Flume Sensor Add support for Flume API and sensor * Add support for choosing timezone Timezone is now a required option in configuration.yaml * Add Flume to coveragerc and CODEOWNERS Add flume to be ommited from testing. Add @ChrisMandich as Flume Code owner * Revert "Add Flume to coveragerc and CODEOWNERS" This reverts commit 0b27437a3b13f024332c6498b3bb0d554482e49b. * Update manifest.json Added Documentation URL for Flume to HASS.IO * Update manifest.json Added missing Newline at EOF. * Update sensor.py Update sensor to not required Device ID for configuration. Now loops through all available Type 2 devices and adds them as an entity. * Update Manifest, CODEOWNERS, and manifest.json Resolved errors related to code owners and requirements. Using hassfest and gen_requirements_all * Update sensor.py Implemented recommendations from @Quentame. Including time zone from Home Assistant, Updated variable names, and Consolidated duplicate functions. * Implemented suggested changes from @Quentame This includes: components name, using f-strings instead of concat, snake_case for variables, constants for the addition of future device types, clearer errors, and removed variables no longer in use. * Update sensor.py Restored unit_of_measurement. Updated return to "gal". * Address pylint errors * Update sensor.py Include protected attributes in setup_platform. * Address Pylint errors homeassistant/components/flume/sensor.py:63:11: W0703: Catching too general exception Exception (broad-except) homeassistant/components/flume/sensor.py:133:8: R1720: Unnecessary "else" after "raise" (no-else-raise) homeassistant/components/flume/sensor.py:162:8: R1705: Unnecessary "else" after "return" (no-else-return) homeassistant/components/flume/sensor.py:236:8: R1720: Unnecessary "else" after "raise" (no-else-raise) * Update sensor.py I'm okay with the broad exception clause. homeassistant/components/flume/sensor.py:65:11: W0703: Catching too general exception Exception (broad-except) * Update sensor.py Add more specific exceptions for Try/Except. * Update Flume Sensory.py add requirements, exclude from tests, us pyflume pypi package. * Update sensor.py to support latest pyflume package * Update manifest provide better flow of manifest and easier readibility. * Update manifest.json Reccomended by @balloob as it is already a core requirement * Update sensor.py Add proposed changes from @balloob * Update requirements_all.txt pytz is a core dependency, removing flume's requirement for it. * Update sensor.py Added @MartinHjelmare recommended changes. * Update sensor.py Resolving PyLint error * Update sensor.py Remove `KeyError`. Add length check for flume entity list before adding. * Update sensor.py * Update pyflume version * Update imports with isort * Add line break between standard library and thirdparty imports. * Remove throttle from sensor.py
2019-11-23 08:55:46 +00:00
if flume_entity_list:
async_add_entities(flume_entity_list)
Add flume support (#27235) * Add Flume Sensor Add support for Flume API and sensor * Add support for choosing timezone Timezone is now a required option in configuration.yaml * Add Flume to coveragerc and CODEOWNERS Add flume to be ommited from testing. Add @ChrisMandich as Flume Code owner * Revert "Add Flume to coveragerc and CODEOWNERS" This reverts commit 0b27437a3b13f024332c6498b3bb0d554482e49b. * Update manifest.json Added Documentation URL for Flume to HASS.IO * Update manifest.json Added missing Newline at EOF. * Update sensor.py Update sensor to not required Device ID for configuration. Now loops through all available Type 2 devices and adds them as an entity. * Update Manifest, CODEOWNERS, and manifest.json Resolved errors related to code owners and requirements. Using hassfest and gen_requirements_all * Update sensor.py Implemented recommendations from @Quentame. Including time zone from Home Assistant, Updated variable names, and Consolidated duplicate functions. * Implemented suggested changes from @Quentame This includes: components name, using f-strings instead of concat, snake_case for variables, constants for the addition of future device types, clearer errors, and removed variables no longer in use. * Update sensor.py Restored unit_of_measurement. Updated return to "gal". * Address pylint errors * Update sensor.py Include protected attributes in setup_platform. * Address Pylint errors homeassistant/components/flume/sensor.py:63:11: W0703: Catching too general exception Exception (broad-except) homeassistant/components/flume/sensor.py:133:8: R1720: Unnecessary "else" after "raise" (no-else-raise) homeassistant/components/flume/sensor.py:162:8: R1705: Unnecessary "else" after "return" (no-else-return) homeassistant/components/flume/sensor.py:236:8: R1720: Unnecessary "else" after "raise" (no-else-raise) * Update sensor.py I'm okay with the broad exception clause. homeassistant/components/flume/sensor.py:65:11: W0703: Catching too general exception Exception (broad-except) * Update sensor.py Add more specific exceptions for Try/Except. * Update Flume Sensory.py add requirements, exclude from tests, us pyflume pypi package. * Update sensor.py to support latest pyflume package * Update manifest provide better flow of manifest and easier readibility. * Update manifest.json Reccomended by @balloob as it is already a core requirement * Update sensor.py Add proposed changes from @balloob * Update requirements_all.txt pytz is a core dependency, removing flume's requirement for it. * Update sensor.py Added @MartinHjelmare recommended changes. * Update sensor.py Resolving PyLint error * Update sensor.py Remove `KeyError`. Add length check for flume entity list before adding. * Update sensor.py * Update pyflume version * Update imports with isort * Add line break between standard library and thirdparty imports. * Remove throttle from sensor.py
2019-11-23 08:55:46 +00:00
class FlumeSensor(CoordinatorEntity, SensorEntity):
Add flume support (#27235) * Add Flume Sensor Add support for Flume API and sensor * Add support for choosing timezone Timezone is now a required option in configuration.yaml * Add Flume to coveragerc and CODEOWNERS Add flume to be ommited from testing. Add @ChrisMandich as Flume Code owner * Revert "Add Flume to coveragerc and CODEOWNERS" This reverts commit 0b27437a3b13f024332c6498b3bb0d554482e49b. * Update manifest.json Added Documentation URL for Flume to HASS.IO * Update manifest.json Added missing Newline at EOF. * Update sensor.py Update sensor to not required Device ID for configuration. Now loops through all available Type 2 devices and adds them as an entity. * Update Manifest, CODEOWNERS, and manifest.json Resolved errors related to code owners and requirements. Using hassfest and gen_requirements_all * Update sensor.py Implemented recommendations from @Quentame. Including time zone from Home Assistant, Updated variable names, and Consolidated duplicate functions. * Implemented suggested changes from @Quentame This includes: components name, using f-strings instead of concat, snake_case for variables, constants for the addition of future device types, clearer errors, and removed variables no longer in use. * Update sensor.py Restored unit_of_measurement. Updated return to "gal". * Address pylint errors * Update sensor.py Include protected attributes in setup_platform. * Address Pylint errors homeassistant/components/flume/sensor.py:63:11: W0703: Catching too general exception Exception (broad-except) homeassistant/components/flume/sensor.py:133:8: R1720: Unnecessary "else" after "raise" (no-else-raise) homeassistant/components/flume/sensor.py:162:8: R1705: Unnecessary "else" after "return" (no-else-return) homeassistant/components/flume/sensor.py:236:8: R1720: Unnecessary "else" after "raise" (no-else-raise) * Update sensor.py I'm okay with the broad exception clause. homeassistant/components/flume/sensor.py:65:11: W0703: Catching too general exception Exception (broad-except) * Update sensor.py Add more specific exceptions for Try/Except. * Update Flume Sensory.py add requirements, exclude from tests, us pyflume pypi package. * Update sensor.py to support latest pyflume package * Update manifest provide better flow of manifest and easier readibility. * Update manifest.json Reccomended by @balloob as it is already a core requirement * Update sensor.py Add proposed changes from @balloob * Update requirements_all.txt pytz is a core dependency, removing flume's requirement for it. * Update sensor.py Added @MartinHjelmare recommended changes. * Update sensor.py Resolving PyLint error * Update sensor.py Remove `KeyError`. Add length check for flume entity list before adding. * Update sensor.py * Update pyflume version * Update imports with isort * Add line break between standard library and thirdparty imports. * Remove throttle from sensor.py
2019-11-23 08:55:46 +00:00
"""Representation of the Flume sensor."""
2021-09-20 16:13:09 +00:00
def __init__(
self,
coordinator,
flume_device,
name,
device_id,
description: SensorEntityDescription,
):
Add flume support (#27235) * Add Flume Sensor Add support for Flume API and sensor * Add support for choosing timezone Timezone is now a required option in configuration.yaml * Add Flume to coveragerc and CODEOWNERS Add flume to be ommited from testing. Add @ChrisMandich as Flume Code owner * Revert "Add Flume to coveragerc and CODEOWNERS" This reverts commit 0b27437a3b13f024332c6498b3bb0d554482e49b. * Update manifest.json Added Documentation URL for Flume to HASS.IO * Update manifest.json Added missing Newline at EOF. * Update sensor.py Update sensor to not required Device ID for configuration. Now loops through all available Type 2 devices and adds them as an entity. * Update Manifest, CODEOWNERS, and manifest.json Resolved errors related to code owners and requirements. Using hassfest and gen_requirements_all * Update sensor.py Implemented recommendations from @Quentame. Including time zone from Home Assistant, Updated variable names, and Consolidated duplicate functions. * Implemented suggested changes from @Quentame This includes: components name, using f-strings instead of concat, snake_case for variables, constants for the addition of future device types, clearer errors, and removed variables no longer in use. * Update sensor.py Restored unit_of_measurement. Updated return to "gal". * Address pylint errors * Update sensor.py Include protected attributes in setup_platform. * Address Pylint errors homeassistant/components/flume/sensor.py:63:11: W0703: Catching too general exception Exception (broad-except) homeassistant/components/flume/sensor.py:133:8: R1720: Unnecessary "else" after "raise" (no-else-raise) homeassistant/components/flume/sensor.py:162:8: R1705: Unnecessary "else" after "return" (no-else-return) homeassistant/components/flume/sensor.py:236:8: R1720: Unnecessary "else" after "raise" (no-else-raise) * Update sensor.py I'm okay with the broad exception clause. homeassistant/components/flume/sensor.py:65:11: W0703: Catching too general exception Exception (broad-except) * Update sensor.py Add more specific exceptions for Try/Except. * Update Flume Sensory.py add requirements, exclude from tests, us pyflume pypi package. * Update sensor.py to support latest pyflume package * Update manifest provide better flow of manifest and easier readibility. * Update manifest.json Reccomended by @balloob as it is already a core requirement * Update sensor.py Add proposed changes from @balloob * Update requirements_all.txt pytz is a core dependency, removing flume's requirement for it. * Update sensor.py Added @MartinHjelmare recommended changes. * Update sensor.py Resolving PyLint error * Update sensor.py Remove `KeyError`. Add length check for flume entity list before adding. * Update sensor.py * Update pyflume version * Update imports with isort * Add line break between standard library and thirdparty imports. * Remove throttle from sensor.py
2019-11-23 08:55:46 +00:00
"""Initialize the Flume sensor."""
super().__init__(coordinator)
2021-09-20 16:13:09 +00:00
self.entity_description = description
self._flume_device = flume_device
2021-09-20 16:13:09 +00:00
self._attr_name = f"{name} {description.name}"
self._attr_unique_id = f"{description.key}_{device_id}"
2021-10-23 10:01:21 +00:00
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, device_id)},
manufacturer="Flume, Inc.",
model="Flume Smart Water Monitor",
name=self.name,
)
Add flume support (#27235) * Add Flume Sensor Add support for Flume API and sensor * Add support for choosing timezone Timezone is now a required option in configuration.yaml * Add Flume to coveragerc and CODEOWNERS Add flume to be ommited from testing. Add @ChrisMandich as Flume Code owner * Revert "Add Flume to coveragerc and CODEOWNERS" This reverts commit 0b27437a3b13f024332c6498b3bb0d554482e49b. * Update manifest.json Added Documentation URL for Flume to HASS.IO * Update manifest.json Added missing Newline at EOF. * Update sensor.py Update sensor to not required Device ID for configuration. Now loops through all available Type 2 devices and adds them as an entity. * Update Manifest, CODEOWNERS, and manifest.json Resolved errors related to code owners and requirements. Using hassfest and gen_requirements_all * Update sensor.py Implemented recommendations from @Quentame. Including time zone from Home Assistant, Updated variable names, and Consolidated duplicate functions. * Implemented suggested changes from @Quentame This includes: components name, using f-strings instead of concat, snake_case for variables, constants for the addition of future device types, clearer errors, and removed variables no longer in use. * Update sensor.py Restored unit_of_measurement. Updated return to "gal". * Address pylint errors * Update sensor.py Include protected attributes in setup_platform. * Address Pylint errors homeassistant/components/flume/sensor.py:63:11: W0703: Catching too general exception Exception (broad-except) homeassistant/components/flume/sensor.py:133:8: R1720: Unnecessary "else" after "raise" (no-else-raise) homeassistant/components/flume/sensor.py:162:8: R1705: Unnecessary "else" after "return" (no-else-return) homeassistant/components/flume/sensor.py:236:8: R1720: Unnecessary "else" after "raise" (no-else-raise) * Update sensor.py I'm okay with the broad exception clause. homeassistant/components/flume/sensor.py:65:11: W0703: Catching too general exception Exception (broad-except) * Update sensor.py Add more specific exceptions for Try/Except. * Update Flume Sensory.py add requirements, exclude from tests, us pyflume pypi package. * Update sensor.py to support latest pyflume package * Update manifest provide better flow of manifest and easier readibility. * Update manifest.json Reccomended by @balloob as it is already a core requirement * Update sensor.py Add proposed changes from @balloob * Update requirements_all.txt pytz is a core dependency, removing flume's requirement for it. * Update sensor.py Added @MartinHjelmare recommended changes. * Update sensor.py Resolving PyLint error * Update sensor.py Remove `KeyError`. Add length check for flume entity list before adding. * Update sensor.py * Update pyflume version * Update imports with isort * Add line break between standard library and thirdparty imports. * Remove throttle from sensor.py
2019-11-23 08:55:46 +00:00
@property
def native_value(self):
Add flume support (#27235) * Add Flume Sensor Add support for Flume API and sensor * Add support for choosing timezone Timezone is now a required option in configuration.yaml * Add Flume to coveragerc and CODEOWNERS Add flume to be ommited from testing. Add @ChrisMandich as Flume Code owner * Revert "Add Flume to coveragerc and CODEOWNERS" This reverts commit 0b27437a3b13f024332c6498b3bb0d554482e49b. * Update manifest.json Added Documentation URL for Flume to HASS.IO * Update manifest.json Added missing Newline at EOF. * Update sensor.py Update sensor to not required Device ID for configuration. Now loops through all available Type 2 devices and adds them as an entity. * Update Manifest, CODEOWNERS, and manifest.json Resolved errors related to code owners and requirements. Using hassfest and gen_requirements_all * Update sensor.py Implemented recommendations from @Quentame. Including time zone from Home Assistant, Updated variable names, and Consolidated duplicate functions. * Implemented suggested changes from @Quentame This includes: components name, using f-strings instead of concat, snake_case for variables, constants for the addition of future device types, clearer errors, and removed variables no longer in use. * Update sensor.py Restored unit_of_measurement. Updated return to "gal". * Address pylint errors * Update sensor.py Include protected attributes in setup_platform. * Address Pylint errors homeassistant/components/flume/sensor.py:63:11: W0703: Catching too general exception Exception (broad-except) homeassistant/components/flume/sensor.py:133:8: R1720: Unnecessary "else" after "raise" (no-else-raise) homeassistant/components/flume/sensor.py:162:8: R1705: Unnecessary "else" after "return" (no-else-return) homeassistant/components/flume/sensor.py:236:8: R1720: Unnecessary "else" after "raise" (no-else-raise) * Update sensor.py I'm okay with the broad exception clause. homeassistant/components/flume/sensor.py:65:11: W0703: Catching too general exception Exception (broad-except) * Update sensor.py Add more specific exceptions for Try/Except. * Update Flume Sensory.py add requirements, exclude from tests, us pyflume pypi package. * Update sensor.py to support latest pyflume package * Update manifest provide better flow of manifest and easier readibility. * Update manifest.json Reccomended by @balloob as it is already a core requirement * Update sensor.py Add proposed changes from @balloob * Update requirements_all.txt pytz is a core dependency, removing flume's requirement for it. * Update sensor.py Added @MartinHjelmare recommended changes. * Update sensor.py Resolving PyLint error * Update sensor.py Remove `KeyError`. Add length check for flume entity list before adding. * Update sensor.py * Update pyflume version * Update imports with isort * Add line break between standard library and thirdparty imports. * Remove throttle from sensor.py
2019-11-23 08:55:46 +00:00
"""Return the state of the sensor."""
2021-09-20 16:13:09 +00:00
sensor_key = self.entity_description.key
if sensor_key not in self._flume_device.values:
return None
return _format_state_value(self._flume_device.values[sensor_key])
Add flume support (#27235) * Add Flume Sensor Add support for Flume API and sensor * Add support for choosing timezone Timezone is now a required option in configuration.yaml * Add Flume to coveragerc and CODEOWNERS Add flume to be ommited from testing. Add @ChrisMandich as Flume Code owner * Revert "Add Flume to coveragerc and CODEOWNERS" This reverts commit 0b27437a3b13f024332c6498b3bb0d554482e49b. * Update manifest.json Added Documentation URL for Flume to HASS.IO * Update manifest.json Added missing Newline at EOF. * Update sensor.py Update sensor to not required Device ID for configuration. Now loops through all available Type 2 devices and adds them as an entity. * Update Manifest, CODEOWNERS, and manifest.json Resolved errors related to code owners and requirements. Using hassfest and gen_requirements_all * Update sensor.py Implemented recommendations from @Quentame. Including time zone from Home Assistant, Updated variable names, and Consolidated duplicate functions. * Implemented suggested changes from @Quentame This includes: components name, using f-strings instead of concat, snake_case for variables, constants for the addition of future device types, clearer errors, and removed variables no longer in use. * Update sensor.py Restored unit_of_measurement. Updated return to "gal". * Address pylint errors * Update sensor.py Include protected attributes in setup_platform. * Address Pylint errors homeassistant/components/flume/sensor.py:63:11: W0703: Catching too general exception Exception (broad-except) homeassistant/components/flume/sensor.py:133:8: R1720: Unnecessary "else" after "raise" (no-else-raise) homeassistant/components/flume/sensor.py:162:8: R1705: Unnecessary "else" after "return" (no-else-return) homeassistant/components/flume/sensor.py:236:8: R1720: Unnecessary "else" after "raise" (no-else-raise) * Update sensor.py I'm okay with the broad exception clause. homeassistant/components/flume/sensor.py:65:11: W0703: Catching too general exception Exception (broad-except) * Update sensor.py Add more specific exceptions for Try/Except. * Update Flume Sensory.py add requirements, exclude from tests, us pyflume pypi package. * Update sensor.py to support latest pyflume package * Update manifest provide better flow of manifest and easier readibility. * Update manifest.json Reccomended by @balloob as it is already a core requirement * Update sensor.py Add proposed changes from @balloob * Update requirements_all.txt pytz is a core dependency, removing flume's requirement for it. * Update sensor.py Added @MartinHjelmare recommended changes. * Update sensor.py Resolving PyLint error * Update sensor.py Remove `KeyError`. Add length check for flume entity list before adding. * Update sensor.py * Update pyflume version * Update imports with isort * Add line break between standard library and thirdparty imports. * Remove throttle from sensor.py
2019-11-23 08:55:46 +00:00
async def async_added_to_hass(self):
"""Request an update when added."""
await super().async_added_to_hass()
# We do not ask for an update with async_add_entities()
# because it will update disabled entities
await self.coordinator.async_request_refresh()
def _format_state_value(value):
return round(value, 1) if isinstance(value, Number) else None
def _create_flume_device_coordinator(hass, flume_device):
"""Create a data coordinator for the flume device."""
async def _async_update_data():
"""Get the latest data from the Flume."""
_LOGGER.debug("Updating Flume data")
try:
await hass.async_add_executor_job(flume_device.update_force)
except Exception as ex:
raise UpdateFailed(f"Error communicating with flume API: {ex}") from ex
_LOGGER.debug(
"Flume update details: %s",
{
"values": flume_device.values,
"query_payload": flume_device.query_payload,
},
)
return DataUpdateCoordinator(
hass,
_LOGGER,
# Name of the data. For logging purposes.
name=flume_device.device_id,
update_method=_async_update_data,
# Polling interval. Will only be polled if there are subscribers.
update_interval=SCAN_INTERVAL,
)