Add and use bunch of data size and rate related constants (#31781)
Also fix a few units to match the corresponding data.
This commit is contained in:
parent
0173c61fee
commit
3e23a3a860
41 changed files with 349 additions and 223 deletions
|
@ -1,6 +1,7 @@
|
|||
"""Asuswrt status sensors."""
|
||||
import logging
|
||||
|
||||
from homeassistant.const import DATA_GIGABYTES, DATA_RATE_MEGABITS_PER_SECOND
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from . import DATA_ASUSWRT
|
||||
|
@ -61,7 +62,7 @@ class AsuswrtRXSensor(AsuswrtSensor):
|
|||
"""Representation of a asuswrt download speed sensor."""
|
||||
|
||||
_name = "Asuswrt Download Speed"
|
||||
_unit = "Mbit/s"
|
||||
_unit = DATA_RATE_MEGABITS_PER_SECOND
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
|
@ -79,7 +80,7 @@ class AsuswrtTXSensor(AsuswrtSensor):
|
|||
"""Representation of a asuswrt upload speed sensor."""
|
||||
|
||||
_name = "Asuswrt Upload Speed"
|
||||
_unit = "Mbit/s"
|
||||
_unit = DATA_RATE_MEGABITS_PER_SECOND
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
|
@ -97,7 +98,7 @@ class AsuswrtTotalRXSensor(AsuswrtSensor):
|
|||
"""Representation of a asuswrt total download sensor."""
|
||||
|
||||
_name = "Asuswrt Download"
|
||||
_unit = "Gigabyte"
|
||||
_unit = DATA_GIGABYTES
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
|
@ -115,7 +116,7 @@ class AsuswrtTotalTXSensor(AsuswrtSensor):
|
|||
"""Representation of a asuswrt total upload sensor."""
|
||||
|
||||
_name = "Asuswrt Upload"
|
||||
_unit = "Gigabyte"
|
||||
_unit = DATA_GIGABYTES
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
|
|
|
@ -11,6 +11,7 @@ from homeassistant.const import (
|
|||
ATTR_ATTRIBUTION,
|
||||
CONF_MONITORED_VARIABLES,
|
||||
CONF_NAME,
|
||||
DATA_RATE_MEGABITS_PER_SECOND,
|
||||
DEVICE_CLASS_TIMESTAMP,
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -20,8 +21,6 @@ from homeassistant.util.dt import utcnow
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
BANDWIDTH_MEGABITS_SECONDS = "Mb/s"
|
||||
|
||||
ATTRIBUTION = "Powered by Bouygues Telecom"
|
||||
|
||||
DEFAULT_NAME = "Bbox"
|
||||
|
@ -32,22 +31,22 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
|
|||
SENSOR_TYPES = {
|
||||
"down_max_bandwidth": [
|
||||
"Maximum Download Bandwidth",
|
||||
BANDWIDTH_MEGABITS_SECONDS,
|
||||
DATA_RATE_MEGABITS_PER_SECOND,
|
||||
"mdi:download",
|
||||
],
|
||||
"up_max_bandwidth": [
|
||||
"Maximum Upload Bandwidth",
|
||||
BANDWIDTH_MEGABITS_SECONDS,
|
||||
DATA_RATE_MEGABITS_PER_SECOND,
|
||||
"mdi:upload",
|
||||
],
|
||||
"current_down_bandwidth": [
|
||||
"Currently Used Download Bandwidth",
|
||||
BANDWIDTH_MEGABITS_SECONDS,
|
||||
DATA_RATE_MEGABITS_PER_SECOND,
|
||||
"mdi:download",
|
||||
],
|
||||
"current_up_bandwidth": [
|
||||
"Currently Used Upload Bandwidth",
|
||||
BANDWIDTH_MEGABITS_SECONDS,
|
||||
DATA_RATE_MEGABITS_PER_SECOND,
|
||||
"mdi:upload",
|
||||
],
|
||||
"uptime": ["Uptime", None, "mdi:clock"],
|
||||
|
|
|
@ -12,6 +12,7 @@ from homeassistant.const import (
|
|||
CONF_PASSWORD,
|
||||
CONF_PORT,
|
||||
CONF_USERNAME,
|
||||
DATA_RATE_KILOBYTES_PER_SECOND,
|
||||
STATE_IDLE,
|
||||
)
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
|
@ -27,8 +28,8 @@ DHT_UPLOAD = 1000
|
|||
DHT_DOWNLOAD = 1000
|
||||
SENSOR_TYPES = {
|
||||
"current_status": ["Status", None],
|
||||
"download_speed": ["Down Speed", "kB/s"],
|
||||
"upload_speed": ["Up Speed", "kB/s"],
|
||||
"download_speed": ["Down Speed", DATA_RATE_KILOBYTES_PER_SECOND],
|
||||
"upload_speed": ["Up Speed", DATA_RATE_KILOBYTES_PER_SECOND],
|
||||
}
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
|
|
|
@ -6,7 +6,7 @@ import re
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import CONF_SENSORS
|
||||
from homeassistant.const import CONF_SENSORS, DATA_GIGABYTES
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
|
@ -26,8 +26,13 @@ SENSORS = {
|
|||
SENSOR_NETWORK: ("signal strength", "Network", None, "mdi:access-point-network"),
|
||||
SENSOR_SIGNAL: ("signal strength", "Signal Strength", "%", "mdi:signal"),
|
||||
SENSOR_SMS_UNREAD: ("sms unread", "SMS unread", "", "mdi:message-text-outline"),
|
||||
SENSOR_UPLOAD: ("traffic modem tx", "Sent", "GB", "mdi:cloud-upload"),
|
||||
SENSOR_DOWNLOAD: ("traffic modem rx", "Received", "GB", "mdi:cloud-download"),
|
||||
SENSOR_UPLOAD: ("traffic modem tx", "Sent", DATA_GIGABYTES, "mdi:cloud-upload"),
|
||||
SENSOR_DOWNLOAD: (
|
||||
"traffic modem rx",
|
||||
"Received",
|
||||
DATA_GIGABYTES,
|
||||
"mdi:cloud-download",
|
||||
),
|
||||
}
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
|
|
|
@ -19,6 +19,7 @@ from homeassistant.const import (
|
|||
CONF_NAME,
|
||||
CONF_PASSWORD,
|
||||
CONF_USERNAME,
|
||||
DATA_GIGABITS,
|
||||
)
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -27,7 +28,6 @@ from homeassistant.util import Throttle
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
GIGABITS = "Gb"
|
||||
PRICE = "CAD"
|
||||
DAYS = "days"
|
||||
PERCENT = "%"
|
||||
|
@ -41,17 +41,21 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=15)
|
|||
SENSOR_TYPES = {
|
||||
"usage": ["Usage", PERCENT, "mdi:percent"],
|
||||
"balance": ["Balance", PRICE, "mdi:square-inc-cash"],
|
||||
"limit": ["Data limit", GIGABITS, "mdi:download"],
|
||||
"limit": ["Data limit", DATA_GIGABITS, "mdi:download"],
|
||||
"days_left": ["Days left", DAYS, "mdi:calendar-today"],
|
||||
"before_offpeak_download": ["Download before offpeak", GIGABITS, "mdi:download"],
|
||||
"before_offpeak_upload": ["Upload before offpeak", GIGABITS, "mdi:upload"],
|
||||
"before_offpeak_total": ["Total before offpeak", GIGABITS, "mdi:download"],
|
||||
"offpeak_download": ["Offpeak download", GIGABITS, "mdi:download"],
|
||||
"offpeak_upload": ["Offpeak Upload", GIGABITS, "mdi:upload"],
|
||||
"offpeak_total": ["Offpeak Total", GIGABITS, "mdi:download"],
|
||||
"download": ["Download", GIGABITS, "mdi:download"],
|
||||
"upload": ["Upload", GIGABITS, "mdi:upload"],
|
||||
"total": ["Total", GIGABITS, "mdi:download"],
|
||||
"before_offpeak_download": [
|
||||
"Download before offpeak",
|
||||
DATA_GIGABITS,
|
||||
"mdi:download",
|
||||
],
|
||||
"before_offpeak_upload": ["Upload before offpeak", DATA_GIGABITS, "mdi:upload"],
|
||||
"before_offpeak_total": ["Total before offpeak", DATA_GIGABITS, "mdi:download"],
|
||||
"offpeak_download": ["Offpeak download", DATA_GIGABITS, "mdi:download"],
|
||||
"offpeak_upload": ["Offpeak Upload", DATA_GIGABITS, "mdi:upload"],
|
||||
"offpeak_total": ["Offpeak Total", DATA_GIGABITS, "mdi:download"],
|
||||
"download": ["Download", DATA_GIGABITS, "mdi:download"],
|
||||
"upload": ["Upload", DATA_GIGABITS, "mdi:upload"],
|
||||
"total": ["Total", DATA_GIGABITS, "mdi:download"],
|
||||
}
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Support for Fast.com internet speed testing sensor."""
|
||||
import logging
|
||||
|
||||
from homeassistant.const import DATA_RATE_MEGABITS_PER_SECOND
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
|
@ -11,8 +12,6 @@ _LOGGER = logging.getLogger(__name__)
|
|||
|
||||
ICON = "mdi:speedometer"
|
||||
|
||||
UNIT_OF_MEASUREMENT = "Mbit/s"
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up the Fast.com sensor."""
|
||||
|
@ -41,7 +40,7 @@ class SpeedtestSensor(RestoreEntity):
|
|||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement of this entity, if any."""
|
||||
return UNIT_OF_MEASUREMENT
|
||||
return DATA_RATE_MEGABITS_PER_SECOND
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
|
|
|
@ -20,6 +20,7 @@ from homeassistant.const import (
|
|||
CONF_NAME,
|
||||
CONF_PASSWORD,
|
||||
CONF_USERNAME,
|
||||
DATA_KILOBITS,
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
@ -27,7 +28,6 @@ from homeassistant.util import Throttle
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
KILOBITS = "Kb"
|
||||
PRICE = "CAD"
|
||||
MESSAGES = "messages"
|
||||
MINUTES = "minutes"
|
||||
|
@ -40,9 +40,9 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=15)
|
|||
SENSOR_TYPES = {
|
||||
"fido_dollar": ["Fido dollar", PRICE, "mdi:square-inc-cash"],
|
||||
"balance": ["Balance", PRICE, "mdi:square-inc-cash"],
|
||||
"data_used": ["Data used", KILOBITS, "mdi:download"],
|
||||
"data_limit": ["Data limit", KILOBITS, "mdi:download"],
|
||||
"data_remaining": ["Data remaining", KILOBITS, "mdi:download"],
|
||||
"data_used": ["Data used", DATA_KILOBITS, "mdi:download"],
|
||||
"data_limit": ["Data limit", DATA_KILOBITS, "mdi:download"],
|
||||
"data_remaining": ["Data remaining", DATA_KILOBITS, "mdi:download"],
|
||||
"text_used": ["Text used", MESSAGES, "mdi:message-text"],
|
||||
"text_limit": ["Text limit", MESSAGES, "mdi:message-text"],
|
||||
"text_remaining": ["Text remaining", MESSAGES, "mdi:message-text"],
|
||||
|
|
|
@ -6,6 +6,7 @@ import os
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import DATA_MEGABYTES
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
|
@ -42,7 +43,7 @@ class Filesize(Entity):
|
|||
self._size = None
|
||||
self._last_updated = None
|
||||
self._name = path.split("/")[-1]
|
||||
self._unit_of_measurement = "MB"
|
||||
self._unit_of_measurement = DATA_MEGABYTES
|
||||
|
||||
def update(self):
|
||||
"""Update the sensor."""
|
||||
|
|
|
@ -7,6 +7,7 @@ import os
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import DATA_MEGABYTES
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
|
@ -63,7 +64,7 @@ class Folder(Entity):
|
|||
self._number_of_files = None
|
||||
self._size = None
|
||||
self._name = os.path.split(os.path.split(folder_path)[0])[1]
|
||||
self._unit_of_measurement = "MB"
|
||||
self._unit_of_measurement = DATA_MEGABYTES
|
||||
self._file_list = None
|
||||
|
||||
def update(self):
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Support for Freebox devices (Freebox v6 and Freebox mini 4K)."""
|
||||
import logging
|
||||
|
||||
from homeassistant.const import DATA_RATE_KILOBYTES_PER_SECOND
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from . import DATA_FREEBOX
|
||||
|
@ -56,7 +57,7 @@ class FbxRXSensor(FbxSensor):
|
|||
"""Update the Freebox RxSensor."""
|
||||
|
||||
_name = "Freebox download speed"
|
||||
_unit = "KB/s"
|
||||
_unit = DATA_RATE_KILOBYTES_PER_SECOND
|
||||
_icon = "mdi:download-network"
|
||||
|
||||
async def async_update(self):
|
||||
|
@ -70,7 +71,7 @@ class FbxTXSensor(FbxSensor):
|
|||
"""Update the Freebox TxSensor."""
|
||||
|
||||
_name = "Freebox upload speed"
|
||||
_unit = "KB/s"
|
||||
_unit = DATA_RATE_KILOBYTES_PER_SECOND
|
||||
_icon = "mdi:upload-network"
|
||||
|
||||
async def async_update(self):
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
"""Constants for Glances component."""
|
||||
from homeassistant.const import TEMP_CELSIUS
|
||||
from homeassistant.const import DATA_GIBIBYTES, DATA_MEBIBYTES, TEMP_CELSIUS
|
||||
|
||||
DOMAIN = "glances"
|
||||
CONF_VERSION = "version"
|
||||
|
@ -15,14 +15,14 @@ SUPPORTED_VERSIONS = [2, 3]
|
|||
|
||||
SENSOR_TYPES = {
|
||||
"disk_use_percent": ["fs", "used percent", "%", "mdi:harddisk"],
|
||||
"disk_use": ["fs", "used", "GiB", "mdi:harddisk"],
|
||||
"disk_free": ["fs", "free", "GiB", "mdi:harddisk"],
|
||||
"disk_use": ["fs", "used", DATA_GIBIBYTES, "mdi:harddisk"],
|
||||
"disk_free": ["fs", "free", DATA_GIBIBYTES, "mdi:harddisk"],
|
||||
"memory_use_percent": ["mem", "RAM used percent", "%", "mdi:memory"],
|
||||
"memory_use": ["mem", "RAM used", "MiB", "mdi:memory"],
|
||||
"memory_free": ["mem", "RAM free", "MiB", "mdi:memory"],
|
||||
"memory_use": ["mem", "RAM used", DATA_MEBIBYTES, "mdi:memory"],
|
||||
"memory_free": ["mem", "RAM free", DATA_MEBIBYTES, "mdi:memory"],
|
||||
"swap_use_percent": ["memswap", "Swap used percent", "%", "mdi:memory"],
|
||||
"swap_use": ["memswap", "Swap used", "GiB", "mdi:memory"],
|
||||
"swap_free": ["memswap", "Swap free", "GiB", "mdi:memory"],
|
||||
"swap_use": ["memswap", "Swap used", DATA_GIBIBYTES, "mdi:memory"],
|
||||
"swap_free": ["memswap", "Swap free", DATA_GIBIBYTES, "mdi:memory"],
|
||||
"processor_load": ["load", "CPU load", "15 min", "mdi:memory"],
|
||||
"process_running": ["processcount", "Running", "Count", "mdi:memory"],
|
||||
"process_total": ["processcount", "Total", "Count", "mdi:memory"],
|
||||
|
@ -32,5 +32,10 @@ SENSOR_TYPES = {
|
|||
"sensor_temp": ["sensors", "Temp", TEMP_CELSIUS, "mdi:thermometer"],
|
||||
"docker_active": ["docker", "Containers active", "", "mdi:docker"],
|
||||
"docker_cpu_use": ["docker", "Containers CPU used", "%", "mdi:docker"],
|
||||
"docker_memory_use": ["docker", "Containers RAM used", "MiB", "mdi:docker"],
|
||||
"docker_memory_use": [
|
||||
"docker",
|
||||
"Containers RAM used",
|
||||
DATA_MEBIBYTES,
|
||||
"mdi:docker",
|
||||
],
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ DEFAULT_NOTIFY_SERVICE_NAME = DOMAIN
|
|||
UPDATE_SIGNAL = f"{DOMAIN}_update"
|
||||
UPDATE_OPTIONS_SIGNAL = f"{DOMAIN}_options_update"
|
||||
|
||||
UNIT_BYTES = "B"
|
||||
UNIT_SECONDS = "s"
|
||||
|
||||
CONNECTION_TIMEOUT = 10
|
||||
|
|
|
@ -10,7 +10,7 @@ from homeassistant.components.sensor import (
|
|||
DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||
DOMAIN as SENSOR_DOMAIN,
|
||||
)
|
||||
from homeassistant.const import CONF_URL, STATE_UNKNOWN
|
||||
from homeassistant.const import CONF_URL, DATA_BYTES, STATE_UNKNOWN
|
||||
|
||||
from . import HuaweiLteBaseEntity
|
||||
from .const import (
|
||||
|
@ -18,7 +18,6 @@ from .const import (
|
|||
KEY_DEVICE_INFORMATION,
|
||||
KEY_DEVICE_SIGNAL,
|
||||
KEY_MONITORING_TRAFFIC_STATISTICS,
|
||||
UNIT_BYTES,
|
||||
UNIT_SECONDS,
|
||||
)
|
||||
|
||||
|
@ -126,19 +125,19 @@ SENSOR_META = {
|
|||
name="Current connection duration", unit=UNIT_SECONDS, icon="mdi:timer"
|
||||
),
|
||||
(KEY_MONITORING_TRAFFIC_STATISTICS, "CurrentDownload"): dict(
|
||||
name="Current connection download", unit=UNIT_BYTES, icon="mdi:download"
|
||||
name="Current connection download", unit=DATA_BYTES, icon="mdi:download"
|
||||
),
|
||||
(KEY_MONITORING_TRAFFIC_STATISTICS, "CurrentUpload"): dict(
|
||||
name="Current connection upload", unit=UNIT_BYTES, icon="mdi:upload"
|
||||
name="Current connection upload", unit=DATA_BYTES, icon="mdi:upload"
|
||||
),
|
||||
(KEY_MONITORING_TRAFFIC_STATISTICS, "TotalConnectTime"): dict(
|
||||
name="Total connected duration", unit=UNIT_SECONDS, icon="mdi:timer"
|
||||
),
|
||||
(KEY_MONITORING_TRAFFIC_STATISTICS, "TotalDownload"): dict(
|
||||
name="Total download", unit=UNIT_BYTES, icon="mdi:download"
|
||||
name="Total download", unit=DATA_BYTES, icon="mdi:download"
|
||||
),
|
||||
(KEY_MONITORING_TRAFFIC_STATISTICS, "TotalUpload"): dict(
|
||||
name="Total upload", unit=UNIT_BYTES, icon="mdi:upload"
|
||||
name="Total upload", unit=DATA_BYTES, icon="mdi:upload"
|
||||
),
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ from homeassistant.const import (
|
|||
CONF_PORT,
|
||||
CONF_PROTOCOL,
|
||||
CONF_SCAN_INTERVAL,
|
||||
DATA_RATE_MEGABITS_PER_SECOND,
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.discovery import async_load_platform
|
||||
|
@ -39,11 +40,9 @@ ATTR_UPLOAD = "upload"
|
|||
ATTR_VERSION = "Version"
|
||||
ATTR_HOST = "host"
|
||||
|
||||
UNIT_OF_MEASUREMENT = "Mbit/s"
|
||||
|
||||
SENSOR_TYPES = {
|
||||
ATTR_DOWNLOAD: [ATTR_DOWNLOAD.capitalize(), UNIT_OF_MEASUREMENT],
|
||||
ATTR_UPLOAD: [ATTR_UPLOAD.capitalize(), UNIT_OF_MEASUREMENT],
|
||||
ATTR_DOWNLOAD: [ATTR_DOWNLOAD.capitalize(), DATA_RATE_MEGABITS_PER_SECOND],
|
||||
ATTR_UPLOAD: [ATTR_UPLOAD.capitalize(), DATA_RATE_MEGABITS_PER_SECOND],
|
||||
}
|
||||
|
||||
PROTOCOLS = ["tcp", "udp"]
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Define possible sensor types."""
|
||||
|
||||
from homeassistant.components.binary_sensor import DEVICE_CLASS_CONNECTIVITY
|
||||
from homeassistant.const import DATA_MEBIBYTES
|
||||
|
||||
SENSOR_SMS = "sms"
|
||||
SENSOR_SMS_TOTAL = "sms_total"
|
||||
|
@ -9,7 +10,7 @@ SENSOR_USAGE = "usage"
|
|||
SENSOR_UNITS = {
|
||||
SENSOR_SMS: "unread",
|
||||
SENSOR_SMS_TOTAL: "messages",
|
||||
SENSOR_USAGE: "MiB",
|
||||
SENSOR_USAGE: DATA_MEBIBYTES,
|
||||
"radio_quality": "%",
|
||||
"rx_level": "dBm",
|
||||
"tx_level": "dBm",
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Monitor the NZBGet API."""
|
||||
import logging
|
||||
|
||||
from homeassistant.const import DATA_MEGABYTES, DATA_RATE_MEGABYTES_PER_SECOND
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
@ -12,15 +13,19 @@ _LOGGER = logging.getLogger(__name__)
|
|||
DEFAULT_NAME = "NZBGet"
|
||||
|
||||
SENSOR_TYPES = {
|
||||
"article_cache": ["ArticleCacheMB", "Article Cache", "MB"],
|
||||
"average_download_rate": ["AverageDownloadRate", "Average Speed", "MB/s"],
|
||||
"article_cache": ["ArticleCacheMB", "Article Cache", DATA_MEGABYTES],
|
||||
"average_download_rate": [
|
||||
"AverageDownloadRate",
|
||||
"Average Speed",
|
||||
DATA_RATE_MEGABYTES_PER_SECOND,
|
||||
],
|
||||
"download_paused": ["DownloadPaused", "Download Paused", None],
|
||||
"download_rate": ["DownloadRate", "Speed", "MB/s"],
|
||||
"download_size": ["DownloadedSizeMB", "Size", "MB"],
|
||||
"free_disk_space": ["FreeDiskSpaceMB", "Disk Free", "MB"],
|
||||
"download_rate": ["DownloadRate", "Speed", DATA_RATE_MEGABYTES_PER_SECOND],
|
||||
"download_size": ["DownloadedSizeMB", "Size", DATA_MEGABYTES],
|
||||
"free_disk_space": ["FreeDiskSpaceMB", "Disk Free", DATA_MEGABYTES],
|
||||
"post_job_count": ["PostJobCount", "Post Processing Jobs", "Jobs"],
|
||||
"post_paused": ["PostPaused", "Post Processing Paused", None],
|
||||
"remaining_size": ["RemainingSizeMB", "Queue Size", "MB"],
|
||||
"remaining_size": ["RemainingSizeMB", "Queue Size", DATA_MEGABYTES],
|
||||
"uptime": ["UpTimeSec", "Uptime", "min"],
|
||||
}
|
||||
|
||||
|
|
|
@ -10,5 +10,5 @@ set_speed:
|
|||
description: Set download speed limit
|
||||
fields:
|
||||
speed:
|
||||
description: Speed limit in KB/s. 0 is unlimited.
|
||||
description: Speed limit in kB/s. 0 is unlimited.
|
||||
example: 1000
|
|
@ -16,6 +16,7 @@ from homeassistant.const import (
|
|||
CONF_SSL,
|
||||
CONF_USERNAME,
|
||||
CONTENT_TYPE_JSON,
|
||||
DATA_RATE_MEGABYTES_PER_SECOND,
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
@ -29,7 +30,7 @@ DEFAULT_PORT = 8000
|
|||
|
||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=15)
|
||||
|
||||
SENSOR_TYPES = {"speed": ["speed", "Speed", "MB/s"]}
|
||||
SENSOR_TYPES = {"speed": ["speed", "Speed", DATA_RATE_MEGABYTES_PER_SECOND]}
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
|
|
|
@ -11,6 +11,7 @@ from homeassistant.const import (
|
|||
CONF_PASSWORD,
|
||||
CONF_URL,
|
||||
CONF_USERNAME,
|
||||
DATA_RATE_KILOBYTES_PER_SECOND,
|
||||
STATE_IDLE,
|
||||
)
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
|
@ -27,8 +28,8 @@ DEFAULT_NAME = "qBittorrent"
|
|||
|
||||
SENSOR_TYPES = {
|
||||
SENSOR_TYPE_CURRENT_STATUS: ["Status", None],
|
||||
SENSOR_TYPE_DOWNLOAD_SPEED: ["Down Speed", "kB/s"],
|
||||
SENSOR_TYPE_UPLOAD_SPEED: ["Up Speed", "kB/s"],
|
||||
SENSOR_TYPE_DOWNLOAD_SPEED: ["Down Speed", DATA_RATE_KILOBYTES_PER_SECOND],
|
||||
SENSOR_TYPE_UPLOAD_SPEED: ["Up Speed", DATA_RATE_KILOBYTES_PER_SECOND],
|
||||
}
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
|
|
|
@ -16,6 +16,8 @@ from homeassistant.const import (
|
|||
CONF_TIMEOUT,
|
||||
CONF_USERNAME,
|
||||
CONF_VERIFY_SSL,
|
||||
DATA_GIBIBYTES,
|
||||
DATA_RATE_MEBIBYTES_PER_SECOND,
|
||||
TEMP_CELSIUS,
|
||||
)
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
|
@ -62,22 +64,22 @@ _CPU_MON_COND = {
|
|||
"cpu_usage": ["CPU Usage", "%", "mdi:chip"],
|
||||
}
|
||||
_MEMORY_MON_COND = {
|
||||
"memory_free": ["Memory Available", "GB", "mdi:memory"],
|
||||
"memory_used": ["Memory Used", "GB", "mdi:memory"],
|
||||
"memory_free": ["Memory Available", DATA_GIBIBYTES, "mdi:memory"],
|
||||
"memory_used": ["Memory Used", DATA_GIBIBYTES, "mdi:memory"],
|
||||
"memory_percent_used": ["Memory Usage", "%", "mdi:memory"],
|
||||
}
|
||||
_NETWORK_MON_COND = {
|
||||
"network_link_status": ["Network Link", None, "mdi:checkbox-marked-circle-outline"],
|
||||
"network_tx": ["Network Up", "MB/s", "mdi:upload"],
|
||||
"network_rx": ["Network Down", "MB/s", "mdi:download"],
|
||||
"network_tx": ["Network Up", DATA_RATE_MEBIBYTES_PER_SECOND, "mdi:upload"],
|
||||
"network_rx": ["Network Down", DATA_RATE_MEBIBYTES_PER_SECOND, "mdi:download"],
|
||||
}
|
||||
_DRIVE_MON_COND = {
|
||||
"drive_smart_status": ["SMART Status", None, "mdi:checkbox-marked-circle-outline"],
|
||||
"drive_temp": ["Temperature", TEMP_CELSIUS, "mdi:thermometer"],
|
||||
}
|
||||
_VOLUME_MON_COND = {
|
||||
"volume_size_used": ["Used Space", "GB", "mdi:chart-pie"],
|
||||
"volume_size_free": ["Free Space", "GB", "mdi:chart-pie"],
|
||||
"volume_size_used": ["Used Space", DATA_GIBIBYTES, "mdi:chart-pie"],
|
||||
"volume_size_free": ["Free Space", DATA_GIBIBYTES, "mdi:chart-pie"],
|
||||
"volume_percentage_used": ["Volume Used", "%", "mdi:chart-pie"],
|
||||
}
|
||||
|
||||
|
@ -270,7 +272,7 @@ class QNAPMemorySensor(QNAPSensor):
|
|||
if self._api.data:
|
||||
data = self._api.data["system_stats"]["memory"]
|
||||
size = round_nicely(float(data["total"]) / 1024)
|
||||
return {ATTR_MEMORY_SIZE: f"{size} GB"}
|
||||
return {ATTR_MEMORY_SIZE: f"{size} {DATA_GIBIBYTES}"}
|
||||
|
||||
|
||||
class QNAPNetworkSensor(QNAPSensor):
|
||||
|
@ -399,4 +401,6 @@ class QNAPVolumeSensor(QNAPSensor):
|
|||
data = self._api.data["volumes"][self.monitor_device]
|
||||
total_gb = int(data["total_size"]) / 1024 / 1024 / 1024
|
||||
|
||||
return {ATTR_VOLUME_SIZE: "{} GB".format(round_nicely(total_gb))}
|
||||
return {
|
||||
ATTR_VOLUME_SIZE: "{} {}".format(round_nicely(total_gb), DATA_GIBIBYTES)
|
||||
}
|
||||
|
|
|
@ -14,6 +14,15 @@ from homeassistant.const import (
|
|||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_PORT,
|
||||
CONF_SSL,
|
||||
DATA_BYTES,
|
||||
DATA_EXABYTES,
|
||||
DATA_GIGABYTES,
|
||||
DATA_KILOBYTES,
|
||||
DATA_MEGABYTES,
|
||||
DATA_PETABYTES,
|
||||
DATA_TERABYTES,
|
||||
DATA_YOTTABYTES,
|
||||
DATA_ZETTABYTES,
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
@ -29,12 +38,12 @@ DEFAULT_HOST = "localhost"
|
|||
DEFAULT_PORT = 7878
|
||||
DEFAULT_URLBASE = ""
|
||||
DEFAULT_DAYS = "1"
|
||||
DEFAULT_UNIT = "GB"
|
||||
DEFAULT_UNIT = DATA_GIGABYTES
|
||||
|
||||
SCAN_INTERVAL = timedelta(minutes=10)
|
||||
|
||||
SENSOR_TYPES = {
|
||||
"diskspace": ["Disk Space", "GB", "mdi:harddisk"],
|
||||
"diskspace": ["Disk Space", DATA_GIGABYTES, "mdi:harddisk"],
|
||||
"upcoming": ["Upcoming", "Movies", "mdi:television"],
|
||||
"wanted": ["Wanted", "Movies", "mdi:television"],
|
||||
"movies": ["Movies", "Movies", "mdi:television"],
|
||||
|
@ -51,7 +60,17 @@ ENDPOINTS = {
|
|||
}
|
||||
|
||||
# Support to Yottabytes for the future, why not
|
||||
BYTE_SIZES = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
|
||||
BYTE_SIZES = [
|
||||
DATA_BYTES,
|
||||
DATA_KILOBYTES,
|
||||
DATA_MEGABYTES,
|
||||
DATA_GIGABYTES,
|
||||
DATA_TERABYTES,
|
||||
DATA_PETABYTES,
|
||||
DATA_EXABYTES,
|
||||
DATA_ZETTABYTES,
|
||||
DATA_YOTTABYTES,
|
||||
]
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_API_KEY): cv.string,
|
||||
|
|
|
@ -9,6 +9,7 @@ from homeassistant.const import (
|
|||
CONF_MONITORED_VARIABLES,
|
||||
CONF_NAME,
|
||||
CONF_URL,
|
||||
DATA_RATE_KILOBYTES_PER_SECOND,
|
||||
STATE_IDLE,
|
||||
)
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
|
@ -24,8 +25,8 @@ SENSOR_TYPE_UPLOAD_SPEED = "upload_speed"
|
|||
DEFAULT_NAME = "rtorrent"
|
||||
SENSOR_TYPES = {
|
||||
SENSOR_TYPE_CURRENT_STATUS: ["Status", None],
|
||||
SENSOR_TYPE_DOWNLOAD_SPEED: ["Down Speed", "kB/s"],
|
||||
SENSOR_TYPE_UPLOAD_SPEED: ["Up Speed", "kB/s"],
|
||||
SENSOR_TYPE_DOWNLOAD_SPEED: ["Down Speed", DATA_RATE_KILOBYTES_PER_SECOND],
|
||||
SENSOR_TYPE_UPLOAD_SPEED: ["Up Speed", DATA_RATE_KILOBYTES_PER_SECOND],
|
||||
}
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
|
|
|
@ -14,6 +14,9 @@ from homeassistant.const import (
|
|||
CONF_PORT,
|
||||
CONF_SENSORS,
|
||||
CONF_SSL,
|
||||
DATA_GIGABYTES,
|
||||
DATA_MEGABYTES,
|
||||
DATA_RATE_MEGABYTES_PER_SECOND,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import discovery
|
||||
|
@ -49,16 +52,16 @@ SIGNAL_SABNZBD_UPDATED = "sabnzbd_updated"
|
|||
|
||||
SENSOR_TYPES = {
|
||||
"current_status": ["Status", None, "status"],
|
||||
"speed": ["Speed", "MB/s", "kbpersec"],
|
||||
"queue_size": ["Queue", "MB", "mb"],
|
||||
"queue_remaining": ["Left", "MB", "mbleft"],
|
||||
"disk_size": ["Disk", "GB", "diskspacetotal1"],
|
||||
"disk_free": ["Disk Free", "GB", "diskspace1"],
|
||||
"speed": ["Speed", DATA_RATE_MEGABYTES_PER_SECOND, "kbpersec"],
|
||||
"queue_size": ["Queue", DATA_MEGABYTES, "mb"],
|
||||
"queue_remaining": ["Left", DATA_MEGABYTES, "mbleft"],
|
||||
"disk_size": ["Disk", DATA_GIGABYTES, "diskspacetotal1"],
|
||||
"disk_free": ["Disk Free", DATA_GIGABYTES, "diskspace1"],
|
||||
"queue_count": ["Queue Count", None, "noofslots_total"],
|
||||
"day_size": ["Daily Total", "GB", "day_size"],
|
||||
"week_size": ["Weekly Total", "GB", "week_size"],
|
||||
"month_size": ["Monthly Total", "GB", "month_size"],
|
||||
"total_size": ["Total", "GB", "total_size"],
|
||||
"day_size": ["Daily Total", DATA_GIGABYTES, "day_size"],
|
||||
"week_size": ["Weekly Total", DATA_GIGABYTES, "week_size"],
|
||||
"month_size": ["Monthly Total", DATA_GIGABYTES, "month_size"],
|
||||
"total_size": ["Total", DATA_GIGABYTES, "total_size"],
|
||||
}
|
||||
|
||||
SPEED_LIMIT_SCHEMA = vol.Schema(
|
||||
|
|
|
@ -14,6 +14,15 @@ from homeassistant.const import (
|
|||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_PORT,
|
||||
CONF_SSL,
|
||||
DATA_BYTES,
|
||||
DATA_EXABYTES,
|
||||
DATA_GIGABYTES,
|
||||
DATA_KILOBYTES,
|
||||
DATA_MEGABYTES,
|
||||
DATA_PETABYTES,
|
||||
DATA_TERABYTES,
|
||||
DATA_YOTTABYTES,
|
||||
DATA_ZETTABYTES,
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
@ -29,10 +38,10 @@ DEFAULT_HOST = "localhost"
|
|||
DEFAULT_PORT = 8989
|
||||
DEFAULT_URLBASE = ""
|
||||
DEFAULT_DAYS = "1"
|
||||
DEFAULT_UNIT = "GB"
|
||||
DEFAULT_UNIT = DATA_GIGABYTES
|
||||
|
||||
SENSOR_TYPES = {
|
||||
"diskspace": ["Disk Space", "GB", "mdi:harddisk"],
|
||||
"diskspace": ["Disk Space", DATA_GIGABYTES, "mdi:harddisk"],
|
||||
"queue": ["Queue", "Episodes", "mdi:download"],
|
||||
"upcoming": ["Upcoming", "Episodes", "mdi:television"],
|
||||
"wanted": ["Wanted", "Episodes", "mdi:television"],
|
||||
|
@ -52,7 +61,17 @@ ENDPOINTS = {
|
|||
}
|
||||
|
||||
# Support to Yottabytes for the future, why not
|
||||
BYTE_SIZES = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
|
||||
BYTE_SIZES = [
|
||||
DATA_BYTES,
|
||||
DATA_KILOBYTES,
|
||||
DATA_MEGABYTES,
|
||||
DATA_GIGABYTES,
|
||||
DATA_TERABYTES,
|
||||
DATA_PETABYTES,
|
||||
DATA_EXABYTES,
|
||||
DATA_ZETTABYTES,
|
||||
DATA_YOTTABYTES,
|
||||
]
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_API_KEY): cv.string,
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
"""Consts used by Speedtest.net."""
|
||||
|
||||
from homeassistant.const import DATA_RATE_MEGABITS_PER_SECOND
|
||||
|
||||
DOMAIN = "speedtestdotnet"
|
||||
DATA_UPDATED = f"{DOMAIN}_data_updated"
|
||||
|
||||
SENSOR_TYPES = {
|
||||
"ping": ["Ping", "ms"],
|
||||
"download": ["Download", "Mbit/s"],
|
||||
"upload": ["Upload", "Mbit/s"],
|
||||
"download": ["Download", DATA_RATE_MEGABITS_PER_SECOND],
|
||||
"upload": ["Upload", DATA_RATE_MEGABITS_PER_SECOND],
|
||||
}
|
||||
|
|
|
@ -8,7 +8,12 @@ import voluptuous as vol
|
|||
import xmltodict
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import CONF_API_KEY, CONF_MONITORED_VARIABLES, CONF_NAME
|
||||
from homeassistant.const import (
|
||||
CONF_API_KEY,
|
||||
CONF_MONITORED_VARIABLES,
|
||||
CONF_NAME,
|
||||
DATA_GIGABYTES,
|
||||
)
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
@ -19,7 +24,6 @@ _LOGGER = logging.getLogger(__name__)
|
|||
DEFAULT_NAME = "Start.ca"
|
||||
CONF_TOTAL_BANDWIDTH = "total_bandwidth"
|
||||
|
||||
GIGABYTES = "GB"
|
||||
PERCENT = "%"
|
||||
|
||||
MIN_TIME_BETWEEN_UPDATES = timedelta(hours=1)
|
||||
|
@ -27,17 +31,17 @@ REQUEST_TIMEOUT = 5 # seconds
|
|||
|
||||
SENSOR_TYPES = {
|
||||
"usage": ["Usage Ratio", PERCENT, "mdi:percent"],
|
||||
"usage_gb": ["Usage", GIGABYTES, "mdi:download"],
|
||||
"limit": ["Data limit", GIGABYTES, "mdi:download"],
|
||||
"used_download": ["Used Download", GIGABYTES, "mdi:download"],
|
||||
"used_upload": ["Used Upload", GIGABYTES, "mdi:upload"],
|
||||
"used_total": ["Used Total", GIGABYTES, "mdi:download"],
|
||||
"grace_download": ["Grace Download", GIGABYTES, "mdi:download"],
|
||||
"grace_upload": ["Grace Upload", GIGABYTES, "mdi:upload"],
|
||||
"grace_total": ["Grace Total", GIGABYTES, "mdi:download"],
|
||||
"total_download": ["Total Download", GIGABYTES, "mdi:download"],
|
||||
"total_upload": ["Total Upload", GIGABYTES, "mdi:download"],
|
||||
"used_remaining": ["Remaining", GIGABYTES, "mdi:download"],
|
||||
"usage_gb": ["Usage", DATA_GIGABYTES, "mdi:download"],
|
||||
"limit": ["Data limit", DATA_GIGABYTES, "mdi:download"],
|
||||
"used_download": ["Used Download", DATA_GIGABYTES, "mdi:download"],
|
||||
"used_upload": ["Used Upload", DATA_GIGABYTES, "mdi:upload"],
|
||||
"used_total": ["Used Total", DATA_GIGABYTES, "mdi:download"],
|
||||
"grace_download": ["Grace Download", DATA_GIGABYTES, "mdi:download"],
|
||||
"grace_upload": ["Grace Upload", DATA_GIGABYTES, "mdi:upload"],
|
||||
"grace_total": ["Grace Total", DATA_GIGABYTES, "mdi:download"],
|
||||
"total_download": ["Total Download", DATA_GIGABYTES, "mdi:download"],
|
||||
"total_upload": ["Total Upload", DATA_GIGABYTES, "mdi:download"],
|
||||
"used_remaining": ["Remaining", DATA_GIGABYTES, "mdi:download"],
|
||||
}
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
|
|
|
@ -17,6 +17,8 @@ from homeassistant.const import (
|
|||
CONF_PORT,
|
||||
CONF_SSL,
|
||||
CONF_USERNAME,
|
||||
DATA_MEGABYTES,
|
||||
DATA_RATE_KILOBYTES_PER_SECOND,
|
||||
EVENT_HOMEASSISTANT_START,
|
||||
TEMP_CELSIUS,
|
||||
)
|
||||
|
@ -43,14 +45,14 @@ _UTILISATION_MON_COND = {
|
|||
"cpu_5min_load": ["CPU Load (5 min)", "%", "mdi:chip"],
|
||||
"cpu_15min_load": ["CPU Load (15 min)", "%", "mdi:chip"],
|
||||
"memory_real_usage": ["Memory Usage (Real)", "%", "mdi:memory"],
|
||||
"memory_size": ["Memory Size", "Mb", "mdi:memory"],
|
||||
"memory_cached": ["Memory Cached", "Mb", "mdi:memory"],
|
||||
"memory_available_swap": ["Memory Available (Swap)", "Mb", "mdi:memory"],
|
||||
"memory_available_real": ["Memory Available (Real)", "Mb", "mdi:memory"],
|
||||
"memory_total_swap": ["Memory Total (Swap)", "Mb", "mdi:memory"],
|
||||
"memory_total_real": ["Memory Total (Real)", "Mb", "mdi:memory"],
|
||||
"network_up": ["Network Up", "Kbps", "mdi:upload"],
|
||||
"network_down": ["Network Down", "Kbps", "mdi:download"],
|
||||
"memory_size": ["Memory Size", DATA_MEGABYTES, "mdi:memory"],
|
||||
"memory_cached": ["Memory Cached", DATA_MEGABYTES, "mdi:memory"],
|
||||
"memory_available_swap": ["Memory Available (Swap)", DATA_MEGABYTES, "mdi:memory"],
|
||||
"memory_available_real": ["Memory Available (Real)", DATA_MEGABYTES, "mdi:memory"],
|
||||
"memory_total_swap": ["Memory Total (Swap)", DATA_MEGABYTES, "mdi:memory"],
|
||||
"memory_total_real": ["Memory Total (Real)", DATA_MEGABYTES, "mdi:memory"],
|
||||
"network_up": ["Network Up", DATA_RATE_KILOBYTES_PER_SECOND, "mdi:upload"],
|
||||
"network_down": ["Network Down", DATA_RATE_KILOBYTES_PER_SECOND, "mdi:download"],
|
||||
}
|
||||
_STORAGE_VOL_MON_COND = {
|
||||
"volume_status": ["Status", None, "mdi:checkbox-marked-circle-outline"],
|
||||
|
|
|
@ -7,7 +7,15 @@ import psutil
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import CONF_RESOURCES, CONF_TYPE, STATE_OFF, STATE_ON
|
||||
from homeassistant.const import (
|
||||
CONF_RESOURCES,
|
||||
CONF_TYPE,
|
||||
DATA_GIBIBYTES,
|
||||
DATA_MEBIBYTES,
|
||||
DATA_RATE_MEGABYTES_PER_SECOND,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
@ -19,8 +27,8 @@ _LOGGER = logging.getLogger(__name__)
|
|||
CONF_ARG = "arg"
|
||||
|
||||
SENSOR_TYPES = {
|
||||
"disk_free": ["Disk free", "GiB", "mdi:harddisk", None],
|
||||
"disk_use": ["Disk use", "GiB", "mdi:harddisk", None],
|
||||
"disk_free": ["Disk free", DATA_GIBIBYTES, "mdi:harddisk", None],
|
||||
"disk_use": ["Disk use", DATA_GIBIBYTES, "mdi:harddisk", None],
|
||||
"disk_use_percent": ["Disk use (percent)", "%", "mdi:harddisk", None],
|
||||
"ipv4_address": ["IPv4 address", "", "mdi:server-network", None],
|
||||
"ipv6_address": ["IPv6 address", "", "mdi:server-network", None],
|
||||
|
@ -28,29 +36,29 @@ SENSOR_TYPES = {
|
|||
"load_15m": ["Load (15m)", " ", "mdi:memory", None],
|
||||
"load_1m": ["Load (1m)", " ", "mdi:memory", None],
|
||||
"load_5m": ["Load (5m)", " ", "mdi:memory", None],
|
||||
"memory_free": ["Memory free", "MiB", "mdi:memory", None],
|
||||
"memory_use": ["Memory use", "MiB", "mdi:memory", None],
|
||||
"memory_free": ["Memory free", DATA_MEBIBYTES, "mdi:memory", None],
|
||||
"memory_use": ["Memory use", DATA_MEBIBYTES, "mdi:memory", None],
|
||||
"memory_use_percent": ["Memory use (percent)", "%", "mdi:memory", None],
|
||||
"network_in": ["Network in", "MiB", "mdi:server-network", None],
|
||||
"network_out": ["Network out", "MiB", "mdi:server-network", None],
|
||||
"network_in": ["Network in", DATA_MEBIBYTES, "mdi:server-network", None],
|
||||
"network_out": ["Network out", DATA_MEBIBYTES, "mdi:server-network", None],
|
||||
"packets_in": ["Packets in", " ", "mdi:server-network", None],
|
||||
"packets_out": ["Packets out", " ", "mdi:server-network", None],
|
||||
"throughput_network_in": [
|
||||
"Network throughput in",
|
||||
"MB/s",
|
||||
DATA_RATE_MEGABYTES_PER_SECOND,
|
||||
"mdi:server-network",
|
||||
None,
|
||||
],
|
||||
"throughput_network_out": [
|
||||
"Network throughput out",
|
||||
"MB/s",
|
||||
DATA_RATE_MEGABYTES_PER_SECOND,
|
||||
"mdi:server-network",
|
||||
None,
|
||||
],
|
||||
"process": ["Process", " ", "mdi:memory", None],
|
||||
"processor_use": ["Processor use", "%", "mdi:memory", None],
|
||||
"swap_free": ["Swap free", "MiB", "mdi:harddisk", None],
|
||||
"swap_use": ["Swap use", "MiB", "mdi:harddisk", None],
|
||||
"swap_free": ["Swap free", DATA_MEBIBYTES, "mdi:harddisk", None],
|
||||
"swap_use": ["Swap use", DATA_MEBIBYTES, "mdi:harddisk", None],
|
||||
"swap_use_percent": ["Swap use (percent)", "%", "mdi:harddisk", None],
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,12 @@ import async_timeout
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import CONF_API_KEY, CONF_MONITORED_VARIABLES, CONF_NAME
|
||||
from homeassistant.const import (
|
||||
CONF_API_KEY,
|
||||
CONF_MONITORED_VARIABLES,
|
||||
CONF_NAME,
|
||||
DATA_GIGABYTES,
|
||||
)
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
@ -17,7 +22,6 @@ _LOGGER = logging.getLogger(__name__)
|
|||
DEFAULT_NAME = "TekSavvy"
|
||||
CONF_TOTAL_BANDWIDTH = "total_bandwidth"
|
||||
|
||||
GIGABYTES = "GB"
|
||||
PERCENT = "%"
|
||||
|
||||
MIN_TIME_BETWEEN_UPDATES = timedelta(hours=1)
|
||||
|
@ -25,15 +29,15 @@ REQUEST_TIMEOUT = 5 # seconds
|
|||
|
||||
SENSOR_TYPES = {
|
||||
"usage": ["Usage Ratio", PERCENT, "mdi:percent"],
|
||||
"usage_gb": ["Usage", GIGABYTES, "mdi:download"],
|
||||
"limit": ["Data limit", GIGABYTES, "mdi:download"],
|
||||
"onpeak_download": ["On Peak Download", GIGABYTES, "mdi:download"],
|
||||
"onpeak_upload": ["On Peak Upload", GIGABYTES, "mdi:upload"],
|
||||
"onpeak_total": ["On Peak Total", GIGABYTES, "mdi:download"],
|
||||
"offpeak_download": ["Off Peak download", GIGABYTES, "mdi:download"],
|
||||
"offpeak_upload": ["Off Peak Upload", GIGABYTES, "mdi:upload"],
|
||||
"offpeak_total": ["Off Peak Total", GIGABYTES, "mdi:download"],
|
||||
"onpeak_remaining": ["Remaining", GIGABYTES, "mdi:download"],
|
||||
"usage_gb": ["Usage", DATA_GIGABYTES, "mdi:download"],
|
||||
"limit": ["Data limit", DATA_GIGABYTES, "mdi:download"],
|
||||
"onpeak_download": ["On Peak Download", DATA_GIGABYTES, "mdi:download"],
|
||||
"onpeak_upload": ["On Peak Upload", DATA_GIGABYTES, "mdi:upload"],
|
||||
"onpeak_total": ["On Peak Total", DATA_GIGABYTES, "mdi:download"],
|
||||
"offpeak_download": ["Off Peak download", DATA_GIGABYTES, "mdi:download"],
|
||||
"offpeak_upload": ["Off Peak Upload", DATA_GIGABYTES, "mdi:upload"],
|
||||
"offpeak_total": ["Off Peak Total", DATA_GIGABYTES, "mdi:download"],
|
||||
"onpeak_remaining": ["Remaining", DATA_GIGABYTES, "mdi:download"],
|
||||
}
|
||||
|
||||
API_HA_MAP = (
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
"""Constants for the Transmission Bittorent Client component."""
|
||||
|
||||
from homeassistant.const import DATA_RATE_MEGABYTES_PER_SECOND
|
||||
|
||||
DOMAIN = "transmission"
|
||||
|
||||
SENSOR_TYPES = {
|
||||
"active_torrents": ["Active Torrents", "Torrents"],
|
||||
"current_status": ["Status", None],
|
||||
"download_speed": ["Down Speed", "MB/s"],
|
||||
"download_speed": ["Down Speed", DATA_RATE_MEGABYTES_PER_SECOND],
|
||||
"paused_torrents": ["Paused Torrents", "Torrents"],
|
||||
"total_torrents": ["Total Torrents", "Torrents"],
|
||||
"upload_speed": ["Up Speed", "MB/s"],
|
||||
"upload_speed": ["Up Speed", DATA_RATE_MEGABYTES_PER_SECOND],
|
||||
"completed_torrents": ["Completed Torrents", "Torrents"],
|
||||
"started_torrents": ["Started Torrents", "Torrents"],
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import logging
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import CONF_MONITORED_CONDITIONS, CONF_NAME
|
||||
from homeassistant.const import CONF_MONITORED_CONDITIONS, CONF_NAME, DATA_GIGABYTES
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
|
@ -21,7 +21,7 @@ DEFAULT_NAME = "Vultr {} {}"
|
|||
MONITORED_CONDITIONS = {
|
||||
ATTR_CURRENT_BANDWIDTH_USED: [
|
||||
"Current Bandwidth Used",
|
||||
"GB",
|
||||
DATA_GIGABYTES,
|
||||
"mdi:chart-histogram",
|
||||
],
|
||||
ATTR_PENDING_CHARGES: ["Pending Charges", "US$", "mdi:currency-usd"],
|
||||
|
|
|
@ -30,4 +30,3 @@ ATTR_UDP_PORT = "udp_port"
|
|||
|
||||
# Units of measurement
|
||||
CURRENT_MA = "mA"
|
||||
DATA_BYTES = "bytes"
|
||||
|
|
|
@ -4,20 +4,13 @@ import logging
|
|||
from typing import Callable, List, Optional, Union
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import DEVICE_CLASS_TIMESTAMP
|
||||
from homeassistant.const import DATA_BYTES, DEVICE_CLASS_TIMESTAMP
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from . import WLED, WLEDDeviceEntity
|
||||
from .const import (
|
||||
ATTR_LED_COUNT,
|
||||
ATTR_MAX_POWER,
|
||||
CURRENT_MA,
|
||||
DATA_BYTES,
|
||||
DATA_WLED_CLIENT,
|
||||
DOMAIN,
|
||||
)
|
||||
from .const import ATTR_LED_COUNT, ATTR_MAX_POWER, CURRENT_MA, DATA_WLED_CLIENT, DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
|
|
@ -378,6 +378,40 @@ MASS_POUNDS: str = "lb"
|
|||
# UV Index units
|
||||
UNIT_UV_INDEX: str = "UV index"
|
||||
|
||||
# Data units
|
||||
DATA_BITS = "bit"
|
||||
DATA_KILOBITS = "kbit"
|
||||
DATA_MEGABITS = "Mbit"
|
||||
DATA_GIGABITS = "Gbit"
|
||||
DATA_BYTES = "B"
|
||||
DATA_KILOBYTES = "kB"
|
||||
DATA_MEGABYTES = "MB"
|
||||
DATA_GIGABYTES = "GB"
|
||||
DATA_TERABYTES = "TB"
|
||||
DATA_PETABYTES = "PB"
|
||||
DATA_EXABYTES = "EB"
|
||||
DATA_ZETTABYTES = "ZB"
|
||||
DATA_YOTTABYTES = "YB"
|
||||
DATA_KIBIBYTES = "KiB"
|
||||
DATA_MEBIBYTES = "MiB"
|
||||
DATA_GIBIBYTES = "GiB"
|
||||
DATA_TEBIBYTES = "TiB"
|
||||
DATA_PEBIBYTES = "PiB"
|
||||
DATA_EXBIBYTES = "EiB"
|
||||
DATA_ZEBIBYTES = "ZiB"
|
||||
DATA_YOBIBYTES = "YiB"
|
||||
DATA_RATE_BITS_PER_SECOND = f"{DATA_BITS}/s"
|
||||
DATA_RATE_KILOBITS_PER_SECOND = f"{DATA_KILOBITS}/s"
|
||||
DATA_RATE_MEGABITS_PER_SECOND = f"{DATA_MEGABITS}/s"
|
||||
DATA_RATE_GIGABITS_PER_SECOND = f"{DATA_GIGABITS}/s"
|
||||
DATA_RATE_BYTES_PER_SECOND = f"{DATA_BYTES}/s"
|
||||
DATA_RATE_KILOBYTES_PER_SECOND = f"{DATA_KILOBYTES}/s"
|
||||
DATA_RATE_MEGABYTES_PER_SECOND = f"{DATA_MEGABYTES}/s"
|
||||
DATA_RATE_GIGABYTES_PER_SECOND = f"{DATA_GIGABYTES}/s"
|
||||
DATA_RATE_KIBIBYTES_PER_SECOND = f"{DATA_KIBIBYTES}/s"
|
||||
DATA_RATE_MEBIBYTES_PER_SECOND = f"{DATA_MEBIBYTES}/s"
|
||||
DATA_RATE_GIBIBYTES_PER_SECOND = f"{DATA_GIBIBYTES}/s"
|
||||
|
||||
# #### SERVICES ####
|
||||
SERVICE_HOMEASSISTANT_STOP = "stop"
|
||||
SERVICE_HOMEASSISTANT_RESTART = "restart"
|
||||
|
|
|
@ -4,6 +4,7 @@ import unittest
|
|||
import pytest
|
||||
|
||||
import homeassistant.components.radarr.sensor as radarr
|
||||
from homeassistant.const import DATA_GIGABYTES
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
@ -218,7 +219,7 @@ class TestRadarrSetup(unittest.TestCase):
|
|||
"platform": "radarr",
|
||||
"api_key": "foo",
|
||||
"days": "2",
|
||||
"unit": "GB",
|
||||
"unit": DATA_GIGABYTES,
|
||||
"include_paths": [],
|
||||
"monitored_conditions": ["diskspace"],
|
||||
}
|
||||
|
@ -227,7 +228,7 @@ class TestRadarrSetup(unittest.TestCase):
|
|||
device.update()
|
||||
assert "263.10" == device.state
|
||||
assert "mdi:harddisk" == device.icon
|
||||
assert "GB" == device.unit_of_measurement
|
||||
assert DATA_GIGABYTES == device.unit_of_measurement
|
||||
assert "Radarr Disk Space" == device.name
|
||||
assert "263.10/465.42GB (56.53%)" == device.device_state_attributes["/data"]
|
||||
|
||||
|
@ -238,7 +239,7 @@ class TestRadarrSetup(unittest.TestCase):
|
|||
"platform": "radarr",
|
||||
"api_key": "foo",
|
||||
"days": "2",
|
||||
"unit": "GB",
|
||||
"unit": DATA_GIGABYTES,
|
||||
"include_paths": ["/data"],
|
||||
"monitored_conditions": ["diskspace"],
|
||||
}
|
||||
|
@ -247,7 +248,7 @@ class TestRadarrSetup(unittest.TestCase):
|
|||
device.update()
|
||||
assert "263.10" == device.state
|
||||
assert "mdi:harddisk" == device.icon
|
||||
assert "GB" == device.unit_of_measurement
|
||||
assert DATA_GIGABYTES == device.unit_of_measurement
|
||||
assert "Radarr Disk Space" == device.name
|
||||
assert "263.10/465.42GB (56.53%)" == device.device_state_attributes["/data"]
|
||||
|
||||
|
@ -258,7 +259,7 @@ class TestRadarrSetup(unittest.TestCase):
|
|||
"platform": "radarr",
|
||||
"api_key": "foo",
|
||||
"days": "2",
|
||||
"unit": "GB",
|
||||
"unit": DATA_GIGABYTES,
|
||||
"include_paths": ["/data"],
|
||||
"monitored_conditions": ["commands"],
|
||||
}
|
||||
|
@ -278,7 +279,7 @@ class TestRadarrSetup(unittest.TestCase):
|
|||
"platform": "radarr",
|
||||
"api_key": "foo",
|
||||
"days": "2",
|
||||
"unit": "GB",
|
||||
"unit": DATA_GIGABYTES,
|
||||
"include_paths": ["/data"],
|
||||
"monitored_conditions": ["movies"],
|
||||
}
|
||||
|
@ -298,7 +299,7 @@ class TestRadarrSetup(unittest.TestCase):
|
|||
"platform": "radarr",
|
||||
"api_key": "foo",
|
||||
"days": "2",
|
||||
"unit": "GB",
|
||||
"unit": DATA_GIGABYTES,
|
||||
"include_paths": ["/data"],
|
||||
"monitored_conditions": ["upcoming"],
|
||||
}
|
||||
|
@ -325,7 +326,7 @@ class TestRadarrSetup(unittest.TestCase):
|
|||
"platform": "radarr",
|
||||
"api_key": "foo",
|
||||
"days": "1",
|
||||
"unit": "GB",
|
||||
"unit": DATA_GIGABYTES,
|
||||
"include_paths": ["/data"],
|
||||
"monitored_conditions": ["upcoming"],
|
||||
}
|
||||
|
@ -348,7 +349,7 @@ class TestRadarrSetup(unittest.TestCase):
|
|||
"platform": "radarr",
|
||||
"api_key": "foo",
|
||||
"days": "2",
|
||||
"unit": "GB",
|
||||
"unit": DATA_GIGABYTES,
|
||||
"include_paths": ["/data"],
|
||||
"monitored_conditions": ["status"],
|
||||
}
|
||||
|
@ -368,7 +369,7 @@ class TestRadarrSetup(unittest.TestCase):
|
|||
"platform": "radarr",
|
||||
"api_key": "foo",
|
||||
"days": "1",
|
||||
"unit": "GB",
|
||||
"unit": DATA_GIGABYTES,
|
||||
"include_paths": ["/data"],
|
||||
"monitored_conditions": ["upcoming"],
|
||||
"ssl": "true",
|
||||
|
@ -393,7 +394,7 @@ class TestRadarrSetup(unittest.TestCase):
|
|||
"platform": "radarr",
|
||||
"api_key": "foo",
|
||||
"days": "1",
|
||||
"unit": "GB",
|
||||
"unit": DATA_GIGABYTES,
|
||||
"include_paths": ["/data"],
|
||||
"monitored_conditions": ["upcoming"],
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import requests_mock
|
|||
|
||||
import homeassistant.components.rest.sensor as rest
|
||||
import homeassistant.components.sensor as sensor
|
||||
from homeassistant.const import DATA_MEGABYTES
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
from homeassistant.helpers.config_validation import template
|
||||
from homeassistant.setup import setup_component
|
||||
|
@ -125,7 +126,7 @@ class TestRestSensorSetup(unittest.TestCase):
|
|||
"method": "GET",
|
||||
"value_template": "{{ value_json.key }}",
|
||||
"name": "foo",
|
||||
"unit_of_measurement": "MB",
|
||||
"unit_of_measurement": DATA_MEGABYTES,
|
||||
"verify_ssl": "true",
|
||||
"timeout": 30,
|
||||
"authentication": "basic",
|
||||
|
@ -153,7 +154,7 @@ class TestRestSensorSetup(unittest.TestCase):
|
|||
"value_template": "{{ value_json.key }}",
|
||||
"payload": '{ "device": "toaster"}',
|
||||
"name": "foo",
|
||||
"unit_of_measurement": "MB",
|
||||
"unit_of_measurement": DATA_MEGABYTES,
|
||||
"verify_ssl": "true",
|
||||
"timeout": 30,
|
||||
"authentication": "basic",
|
||||
|
@ -181,7 +182,7 @@ class TestRestSensor(unittest.TestCase):
|
|||
),
|
||||
)
|
||||
self.name = "foo"
|
||||
self.unit_of_measurement = "MB"
|
||||
self.unit_of_measurement = DATA_MEGABYTES
|
||||
self.device_class = None
|
||||
self.value_template = template("{{ value_json.key }}")
|
||||
self.value_template.hass = self.hass
|
||||
|
|
|
@ -6,6 +6,7 @@ import unittest
|
|||
import pytest
|
||||
|
||||
import homeassistant.components.sonarr.sensor as sonarr
|
||||
from homeassistant.const import DATA_GIGABYTES
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
@ -497,7 +498,7 @@ class TestSonarrSetup(unittest.TestCase):
|
|||
"platform": "sonarr",
|
||||
"api_key": "foo",
|
||||
"days": "2",
|
||||
"unit": "GB",
|
||||
"unit": DATA_GIGABYTES,
|
||||
"include_paths": [],
|
||||
"monitored_conditions": ["diskspace"],
|
||||
}
|
||||
|
@ -506,7 +507,7 @@ class TestSonarrSetup(unittest.TestCase):
|
|||
device.update()
|
||||
assert "263.10" == device.state
|
||||
assert "mdi:harddisk" == device.icon
|
||||
assert "GB" == device.unit_of_measurement
|
||||
assert DATA_GIGABYTES == device.unit_of_measurement
|
||||
assert "Sonarr Disk Space" == device.name
|
||||
assert "263.10/465.42GB (56.53%)" == device.device_state_attributes["/data"]
|
||||
|
||||
|
@ -517,7 +518,7 @@ class TestSonarrSetup(unittest.TestCase):
|
|||
"platform": "sonarr",
|
||||
"api_key": "foo",
|
||||
"days": "2",
|
||||
"unit": "GB",
|
||||
"unit": DATA_GIGABYTES,
|
||||
"include_paths": ["/data"],
|
||||
"monitored_conditions": ["diskspace"],
|
||||
}
|
||||
|
@ -526,7 +527,7 @@ class TestSonarrSetup(unittest.TestCase):
|
|||
device.update()
|
||||
assert "263.10" == device.state
|
||||
assert "mdi:harddisk" == device.icon
|
||||
assert "GB" == device.unit_of_measurement
|
||||
assert DATA_GIGABYTES == device.unit_of_measurement
|
||||
assert "Sonarr Disk Space" == device.name
|
||||
assert "263.10/465.42GB (56.53%)" == device.device_state_attributes["/data"]
|
||||
|
||||
|
@ -537,7 +538,7 @@ class TestSonarrSetup(unittest.TestCase):
|
|||
"platform": "sonarr",
|
||||
"api_key": "foo",
|
||||
"days": "2",
|
||||
"unit": "GB",
|
||||
"unit": DATA_GIGABYTES,
|
||||
"include_paths": ["/data"],
|
||||
"monitored_conditions": ["commands"],
|
||||
}
|
||||
|
@ -557,7 +558,7 @@ class TestSonarrSetup(unittest.TestCase):
|
|||
"platform": "sonarr",
|
||||
"api_key": "foo",
|
||||
"days": "2",
|
||||
"unit": "GB",
|
||||
"unit": DATA_GIGABYTES,
|
||||
"include_paths": ["/data"],
|
||||
"monitored_conditions": ["queue"],
|
||||
}
|
||||
|
@ -577,7 +578,7 @@ class TestSonarrSetup(unittest.TestCase):
|
|||
"platform": "sonarr",
|
||||
"api_key": "foo",
|
||||
"days": "2",
|
||||
"unit": "GB",
|
||||
"unit": DATA_GIGABYTES,
|
||||
"include_paths": ["/data"],
|
||||
"monitored_conditions": ["series"],
|
||||
}
|
||||
|
@ -599,7 +600,7 @@ class TestSonarrSetup(unittest.TestCase):
|
|||
"platform": "sonarr",
|
||||
"api_key": "foo",
|
||||
"days": "2",
|
||||
"unit": "GB",
|
||||
"unit": DATA_GIGABYTES,
|
||||
"include_paths": ["/data"],
|
||||
"monitored_conditions": ["wanted"],
|
||||
}
|
||||
|
@ -621,7 +622,7 @@ class TestSonarrSetup(unittest.TestCase):
|
|||
"platform": "sonarr",
|
||||
"api_key": "foo",
|
||||
"days": "2",
|
||||
"unit": "GB",
|
||||
"unit": DATA_GIGABYTES,
|
||||
"include_paths": ["/data"],
|
||||
"monitored_conditions": ["upcoming"],
|
||||
}
|
||||
|
@ -645,7 +646,7 @@ class TestSonarrSetup(unittest.TestCase):
|
|||
"platform": "sonarr",
|
||||
"api_key": "foo",
|
||||
"days": "1",
|
||||
"unit": "GB",
|
||||
"unit": DATA_GIGABYTES,
|
||||
"include_paths": ["/data"],
|
||||
"monitored_conditions": ["upcoming"],
|
||||
}
|
||||
|
@ -665,7 +666,7 @@ class TestSonarrSetup(unittest.TestCase):
|
|||
"platform": "sonarr",
|
||||
"api_key": "foo",
|
||||
"days": "2",
|
||||
"unit": "GB",
|
||||
"unit": DATA_GIGABYTES,
|
||||
"include_paths": ["/data"],
|
||||
"monitored_conditions": ["status"],
|
||||
}
|
||||
|
@ -685,7 +686,7 @@ class TestSonarrSetup(unittest.TestCase):
|
|||
"platform": "sonarr",
|
||||
"api_key": "foo",
|
||||
"days": "1",
|
||||
"unit": "GB",
|
||||
"unit": DATA_GIGABYTES,
|
||||
"include_paths": ["/data"],
|
||||
"monitored_conditions": ["upcoming"],
|
||||
"ssl": "true",
|
||||
|
@ -707,7 +708,7 @@ class TestSonarrSetup(unittest.TestCase):
|
|||
"platform": "sonarr",
|
||||
"api_key": "foo",
|
||||
"days": "1",
|
||||
"unit": "GB",
|
||||
"unit": DATA_GIGABYTES,
|
||||
"include_paths": ["/data"],
|
||||
"monitored_conditions": ["upcoming"],
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Tests for the Start.ca sensor platform."""
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.components.startca.sensor import StartcaData
|
||||
from homeassistant.const import DATA_GIGABYTES
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
|
||||
|
@ -55,47 +56,47 @@ async def test_capped_setup(hass, aioclient_mock):
|
|||
assert state.state == "76.24"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_usage")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "304.95"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_data_limit")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "400"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_used_download")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "304.95"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_used_upload")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "6.48"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_used_total")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "311.43"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_grace_download")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "304.95"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_grace_upload")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "6.48"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_grace_total")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "311.43"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_total_download")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "304.95"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_total_upload")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "6.48"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_remaining")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "95.05"
|
||||
|
||||
|
||||
|
@ -150,47 +151,47 @@ async def test_unlimited_setup(hass, aioclient_mock):
|
|||
assert state.state == "0"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_usage")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "0.0"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_data_limit")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "inf"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_used_download")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "0.0"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_used_upload")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "0.0"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_used_total")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "0.0"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_grace_download")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "304.95"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_grace_upload")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "6.48"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_grace_total")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "311.43"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_total_download")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "304.95"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_total_upload")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "6.48"
|
||||
|
||||
state = hass.states.get("sensor.start_ca_remaining")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "inf"
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Tests for the TekSavvy sensor platform."""
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.components.teksavvy.sensor import TekSavvyData
|
||||
from homeassistant.const import DATA_GIGABYTES
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
|
||||
|
@ -45,31 +46,31 @@ async def test_capped_setup(hass, aioclient_mock):
|
|||
await async_setup_component(hass, "sensor", {"sensor": config})
|
||||
|
||||
state = hass.states.get("sensor.teksavvy_data_limit")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "400"
|
||||
|
||||
state = hass.states.get("sensor.teksavvy_off_peak_download")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "36.24"
|
||||
|
||||
state = hass.states.get("sensor.teksavvy_off_peak_upload")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "1.58"
|
||||
|
||||
state = hass.states.get("sensor.teksavvy_off_peak_total")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "37.82"
|
||||
|
||||
state = hass.states.get("sensor.teksavvy_on_peak_download")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "226.75"
|
||||
|
||||
state = hass.states.get("sensor.teksavvy_on_peak_upload")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "8.82"
|
||||
|
||||
state = hass.states.get("sensor.teksavvy_on_peak_total")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "235.57"
|
||||
|
||||
state = hass.states.get("sensor.teksavvy_usage_ratio")
|
||||
|
@ -77,11 +78,11 @@ async def test_capped_setup(hass, aioclient_mock):
|
|||
assert state.state == "56.69"
|
||||
|
||||
state = hass.states.get("sensor.teksavvy_usage")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "226.75"
|
||||
|
||||
state = hass.states.get("sensor.teksavvy_remaining")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "173.25"
|
||||
|
||||
|
||||
|
@ -126,35 +127,35 @@ async def test_unlimited_setup(hass, aioclient_mock):
|
|||
await async_setup_component(hass, "sensor", {"sensor": config})
|
||||
|
||||
state = hass.states.get("sensor.teksavvy_data_limit")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "inf"
|
||||
|
||||
state = hass.states.get("sensor.teksavvy_off_peak_download")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "36.24"
|
||||
|
||||
state = hass.states.get("sensor.teksavvy_off_peak_upload")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "1.58"
|
||||
|
||||
state = hass.states.get("sensor.teksavvy_off_peak_total")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "37.82"
|
||||
|
||||
state = hass.states.get("sensor.teksavvy_on_peak_download")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "226.75"
|
||||
|
||||
state = hass.states.get("sensor.teksavvy_on_peak_upload")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "8.82"
|
||||
|
||||
state = hass.states.get("sensor.teksavvy_on_peak_total")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "235.57"
|
||||
|
||||
state = hass.states.get("sensor.teksavvy_usage")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "226.75"
|
||||
|
||||
state = hass.states.get("sensor.teksavvy_usage_ratio")
|
||||
|
@ -162,7 +163,7 @@ async def test_unlimited_setup(hass, aioclient_mock):
|
|||
assert state.state == "0"
|
||||
|
||||
state = hass.states.get("sensor.teksavvy_remaining")
|
||||
assert state.attributes.get("unit_of_measurement") == "GB"
|
||||
assert state.attributes.get("unit_of_measurement") == DATA_GIGABYTES
|
||||
assert state.state == "inf"
|
||||
|
||||
|
||||
|
|
|
@ -10,7 +10,12 @@ import voluptuous as vol
|
|||
from homeassistant.components import vultr as base_vultr
|
||||
from homeassistant.components.vultr import CONF_SUBSCRIPTION
|
||||
import homeassistant.components.vultr.sensor as vultr
|
||||
from homeassistant.const import CONF_MONITORED_CONDITIONS, CONF_NAME, CONF_PLATFORM
|
||||
from homeassistant.const import (
|
||||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_NAME,
|
||||
CONF_PLATFORM,
|
||||
DATA_GIGABYTES,
|
||||
)
|
||||
|
||||
from tests.common import get_test_home_assistant, load_fixture
|
||||
from tests.components.vultr.test_init import VALID_CONFIG
|
||||
|
@ -83,7 +88,7 @@ class TestVultrSensorSetup(unittest.TestCase):
|
|||
|
||||
device.update()
|
||||
|
||||
if device.unit_of_measurement == "GB": # Test Bandwidth Used
|
||||
if device.unit_of_measurement == DATA_GIGABYTES: # Test Bandwidth Used
|
||||
if device.subscription == "576965":
|
||||
assert "Vultr my new server Current Bandwidth Used" == device.name
|
||||
assert "mdi:chart-histogram" == device.icon
|
||||
|
|
|
@ -8,10 +8,9 @@ from homeassistant.components.wled.const import (
|
|||
ATTR_LED_COUNT,
|
||||
ATTR_MAX_POWER,
|
||||
CURRENT_MA,
|
||||
DATA_BYTES,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.const import ATTR_ICON, ATTR_UNIT_OF_MEASUREMENT
|
||||
from homeassistant.const import ATTR_ICON, ATTR_UNIT_OF_MEASUREMENT, DATA_BYTES
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue