Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable network resources by default, handle apparent power #107

Merged
merged 2 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions custom_components/isy994/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@
CONF_ENABLE_VARIABLES,
CONF_NETWORK,
CONF_TLS_VER,
CONF_VAR_SENSOR_STRING,
DEFAULT_TLS_VERSION,
DEFAULT_VAR_SENSOR_STRING,
DOMAIN,
MANUFACTURER,
PLATFORMS,
Expand Down Expand Up @@ -82,13 +80,10 @@ async def async_setup_entry(

# Optional
tls_version = isy_config.get(CONF_TLS_VER)
variable_identifier = isy_options.get(
CONF_VAR_SENSOR_STRING, DEFAULT_VAR_SENSOR_STRING
)
enable_variables = isy_options.get(CONF_ENABLE_VARIABLES, True)
enable_nodeservers = isy_options.get(CONF_ENABLE_NODESERVERS, True)
enable_programs = isy_options.get(CONF_ENABLE_PROGRAMS, True)
enable_networking = isy_options.get(CONF_ENABLE_NETWORKING, True)
enable_networking = isy_options.get(CONF_ENABLE_NETWORKING, False)

if host.scheme == SCHEME_HTTP:
session = aiohttp_client.async_create_clientsession(
Expand Down Expand Up @@ -151,7 +146,7 @@ async def async_setup_entry(
_categorize_programs(isy_data, isy.programs)

if enable_variables and isy.variables.entities:
_categorize_variables(isy_data, isy.variables, variable_identifier)
_categorize_variables(isy_data, isy.variables)
isy_data.devices[CONF_VARIABLES] = _create_service_device_info(
isy, name=CONF_VARIABLES.title(), unique_id=CONF_VARIABLES
)
Expand Down
8 changes: 1 addition & 7 deletions custom_components/isy994/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@
CONF_RESTORE_LIGHT_STATE,
CONF_SENSOR_STRING,
CONF_TLS_VER,
CONF_VAR_SENSOR_STRING,
DEFAULT_IGNORE_STRING,
DEFAULT_RESTORE_LIGHT_STATE,
DEFAULT_SENSOR_STRING,
DEFAULT_TLS_VERSION,
DEFAULT_VAR_SENSOR_STRING,
DOMAIN,
HTTP_PORT,
HTTPS_PORT,
Expand Down Expand Up @@ -321,19 +319,15 @@ async def async_step_init(
)
ignore_string = options.get(CONF_IGNORE_STRING, DEFAULT_IGNORE_STRING)
sensor_string = options.get(CONF_SENSOR_STRING, DEFAULT_SENSOR_STRING)
var_sensor_string = options.get(
CONF_VAR_SENSOR_STRING, DEFAULT_VAR_SENSOR_STRING
)
enable_variables = options.get(CONF_ENABLE_VARIABLES, True)
enable_nodeservers = options.get(CONF_ENABLE_NODESERVERS, True)
enable_programs = options.get(CONF_ENABLE_PROGRAMS, True)
enable_networking = options.get(CONF_ENABLE_NETWORKING, True)
enable_networking = options.get(CONF_ENABLE_NETWORKING, False)

options_schema = vol.Schema(
{
vol.Optional(CONF_IGNORE_STRING, default=ignore_string): str,
vol.Optional(CONF_SENSOR_STRING, default=sensor_string): str,
vol.Optional(CONF_VAR_SENSOR_STRING, default=var_sensor_string): str,
vol.Required(
CONF_RESTORE_LIGHT_STATE, default=restore_light_state
): bool,
Expand Down
2 changes: 0 additions & 2 deletions custom_components/isy994/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,12 @@
CONF_RESTORE_LIGHT_STATE = "restore_light_state"
CONF_SENSOR_STRING = "sensor_string"
CONF_TLS_VER = "tls"
CONF_VAR_SENSOR_STRING = "variable_sensor_string"

DEFAULT_IGNORE_STRING = "{IGNORE ME}"
DEFAULT_SENSOR_STRING = "sensor"
DEFAULT_RESTORE_LIGHT_STATE = False
DEFAULT_TLS_VERSION = "Default"
DEFAULT_PROGRAM_STRING = "HA."
DEFAULT_VAR_SENSOR_STRING = "HA."

KEY_ACTIONS = "actions"
KEY_STATUS = "status"
Expand Down
4 changes: 1 addition & 3 deletions custom_components/isy994/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,7 @@ def _categorize_programs(isy_data: IsyData, programs: Programs) -> None:
isy_data.programs[platform].append(entity)


def _categorize_variables(
isy_data: IsyData, variables: Variables, identifier: str
) -> None:
def _categorize_variables(isy_data: IsyData, variables: Variables) -> None:
"""Gather the ISY Variables to be added as sensors."""
try:
if not (variables.loaded and variables.entities):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/isy994/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
"manufacturer": "Universal Devices Inc."
}
],
"version": "4.0.14"
"version": "4.0.15"
}
11 changes: 2 additions & 9 deletions custom_components/isy994/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,7 @@
ranged_value_to_percentage,
)

from .const import (
BACKLIGHT_MEMORY_FILTER,
CONF_VAR_SENSOR_STRING,
DEFAULT_VAR_SENSOR_STRING,
DOMAIN,
UOM_8_BIT_RANGE,
)
from .const import BACKLIGHT_MEMORY_FILTER, DOMAIN, UOM_8_BIT_RANGE
from .entity import ISYNodeEntity

ISY_MAX_SIZE = (2**32) / 2
Expand Down Expand Up @@ -83,15 +77,14 @@ async def async_setup_entry(
entities: list[
ISYVariableNumberEntity | ISYAuxControlNumberEntity | ISYBacklightNumberEntity
] = []
var_id = config_entry.options.get(CONF_VAR_SENSOR_STRING, DEFAULT_VAR_SENSOR_STRING)

for node in isy_data.variables[Platform.NUMBER]:
step = 10 ** (-1 * node.precision)
min_max = ISY_MAX_SIZE / (10**node.precision)
description = NumberEntityDescription(
key=node.address,
name=node.name,
entity_registry_enabled_default=var_id in node.name,
entity_registry_enabled_default=False,
native_unit_of_measurement=None,
native_step=step,
native_min_value=-min_max,
Expand Down
18 changes: 15 additions & 3 deletions custom_components/isy994/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@
from .const import (
_LOGGER,
DOMAIN,
POWER_VOLT_AMPERE_REACTIVE,
UOM_DOUBLE_TEMP,
UOM_FRIENDLY_NAME,
UOM_INDEX,
UOM_ON_OFF,
UOM_TO_STATES,
UnitOfApparentPower,
)
from .entity import ISYNodeEntity
from .helpers import convert_isy_value_to_hass
Expand All @@ -53,6 +55,9 @@
PROP_STATUS,
}

PROP_CURRENT_POWER = "CPW"
PROP_TOTAL_POWER = "TPW"

# Reference pyisyox.constants.COMMAND_FRIENDLY_NAME for API details.
# Note: "LUMIN"/Illuminance removed, some devices use non-conformant "%" unit
# "VOCLVL"/VOC removed, uses qualitative UOM not ug/m^3
Expand All @@ -63,7 +68,7 @@
"BARPRES": SensorDeviceClass.ATMOSPHERIC_PRESSURE,
"CC": SensorDeviceClass.CURRENT,
"CO2LVL": SensorDeviceClass.CO2,
"CPW": SensorDeviceClass.POWER,
PROP_CURRENT_POWER: SensorDeviceClass.POWER,
"CV": SensorDeviceClass.VOLTAGE,
"DEWPT": SensorDeviceClass.TEMPERATURE,
"DISTANC": SensorDeviceClass.DISTANCE,
Expand All @@ -83,7 +88,7 @@
"SPEED": SensorDeviceClass.SPEED,
"TEMPEXH": SensorDeviceClass.TEMPERATURE,
"TEMPOUT": SensorDeviceClass.TEMPERATURE,
"TPW": SensorDeviceClass.ENERGY,
PROP_TOTAL_POWER: SensorDeviceClass.ENERGY,
"WATERP": SensorDeviceClass.PRESSURE,
"WATERT": SensorDeviceClass.TEMPERATURE,
"WATERTB": SensorDeviceClass.TEMPERATURE,
Expand All @@ -94,7 +99,7 @@
ISY_CONTROL_TO_STATE_CLASS = {
control: (
SensorStateClass.MEASUREMENT
if control != "TPW"
if control != PROP_TOTAL_POWER
else SensorStateClass.TOTAL_INCREASING
)
for control in ISY_CONTROL_TO_DEVICE_CLASS
Expand Down Expand Up @@ -166,6 +171,13 @@ def get_native_uom(
device_class = None
state_class = None

# QUIRK: ISY does not differentiate between real, apparent, or reactive power:
if control == PROP_CURRENT_POWER:
if native_uom == UnitOfApparentPower.VOLT_AMPERE:
device_class = SensorDeviceClass.APPARENT_POWER
elif native_uom == POWER_VOLT_AMPERE_REACTIVE:
device_class = SensorDeviceClass.REACTIVE_POWER

description = SensorEntityDescription(
key=f"{node}_{control}",
device_class=device_class,
Expand Down