Skip to content

Commit

Permalink
Seperate enity by types for better managmens
Browse files Browse the repository at this point in the history
  • Loading branch information
jontofront committed Oct 14, 2024
1 parent 9bba423 commit 2017ce2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
41 changes: 25 additions & 16 deletions custom_components/econet300/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,13 @@
"mixerSetTemp": SensorStateClass.MEASUREMENT,
}

ENTITY_DEVICE_CLASS_MAP = {
ENTITY_SENSOR_DEVICE_CLASS_MAP: dict[str, SensorDeviceClass | None] = {
#############################
######### SENSORS ##########
# SENSORS
#############################
"tempFeeder": SensorDeviceClass.TEMPERATURE,
"tempExternalSensor": SensorDeviceClass.TEMPERATURE,
"tempCO": SensorDeviceClass.TEMPERATURE,
"tempCOSet": NumberDeviceClass.TEMPERATURE,
"tempCWUSet": NumberDeviceClass.TEMPERATURE,
"boilerPower": SensorDeviceClass.POWER_FACTOR,
"fanPower": SensorDeviceClass.POWER_FACTOR,
"tempFlueGas": SensorDeviceClass.TEMPERATURE,
Expand All @@ -216,20 +214,31 @@
"tempUpperBuffer": SensorDeviceClass.TEMPERATURE,
"tempLowerBuffer": SensorDeviceClass.TEMPERATURE,
"signal": SensorDeviceClass.SIGNAL_STRENGTH,
"softVer": "econet_software_version",
"moduleASoftVer": "module_a_software_version",
"moduleBSoftVer": "Module_b_software_version",
"modulePanelSoftVer": "module_panel_software_version",
"moduleLambdaSoftVer": "module_lamda_software_version",
"protocolType": "protocol_type",
"controllerID": "controller_ID",
"valveMixer1": "valve_mixer_1",
"servoMixer1": "servo_mixer_1",
"Status_wifi": "wifi_status",
"main_server": "main_server",
"softVer": None,
"moduleASoftVer": None,
"moduleBSoftVer": None,
"modulePanelSoftVer": None,
"moduleLambdaSoftVer": None,
"protocolType": None,
"controllerID": None,
"valveMixer1": None,
"servoMixer1": None,
"Status_wifi": None,
"main_server": None,
}

ENTITY_NUMBER_SENSOR_DEVICE_CLASS_MAP = {
#############################
###### BINARY SENSORS #######
# NUMBER SENSORS
#############################
"tempCOSet": NumberDeviceClass.TEMPERATURE,
"tempCWUSet": NumberDeviceClass.TEMPERATURE,
}

#############################
# BINARY SENSORS
#############################
ENTITY_BINARY_DEVICE_CLASS_MAP = {
"lighter": BinarySensorDeviceClass.RUNNING,
"weatherControl": BinarySensorDeviceClass.RUNNING,
"unseal": BinarySensorDeviceClass.RUNNING,
Expand Down
4 changes: 2 additions & 2 deletions custom_components/econet300/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
from .common_functions import camel_to_snake
from .const import (
DOMAIN,
ENTITY_DEVICE_CLASS_MAP,
ENTITY_ICON,
ENTITY_MAX_VALUE,
ENTITY_MIN_VALUE,
ENTITY_NUMBER_SENSOR_DEVICE_CLASS_MAP,
ENTITY_STEP,
ENTITY_UNIT_MAP,
ENTITY_VISIBLE,
Expand Down Expand Up @@ -130,7 +130,7 @@ def create_number_entity_description(key: int) -> EconetNumberEntityDescription:
key=key,
translation_key=camel_to_snake(map_key),
icon=ENTITY_ICON.get(map_key),
device_class=ENTITY_DEVICE_CLASS_MAP.get(map_key),
device_class=ENTITY_NUMBER_SENSOR_DEVICE_CLASS_MAP.get(map_key),
native_unit_of_measurement=ENTITY_UNIT_MAP.get(map_key),
entity_registry_visible_default=ENTITY_VISIBLE.get(map_key, True),
min_value=ENTITY_MIN_VALUE.get(map_key),
Expand Down
7 changes: 3 additions & 4 deletions custom_components/econet300/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
AVAILABLE_NUMBER_OF_MIXERS,
DOMAIN,
ENTITY_CATEGORY,
ENTITY_DEVICE_CLASS_MAP,
ENTITY_ICON,
ENTITY_PRECISION,
ENTITY_SENSOR_DEVICE_CLASS_MAP,
ENTITY_UNIT_MAP,
ENTITY_VALUE_PROCESSOR,
MIXER_MAP,
Expand Down Expand Up @@ -84,13 +84,12 @@ def __init__(

def create_entity_description(key: str) -> EconetSensorEntityDescription:
"""Create Econect300 sensor entity based on supplied key."""
# Retrieve map_key from SENSOR_MAP, falling back to the key itself
map_key = SENSOR_MAP.get(key, key)
_LOGGER.debug("SENSOR_MAP: %s", SENSOR_MAP)
_LOGGER.debug("Creating entity description for key: %s, map_key: %s", key, map_key)
entity_description = EconetSensorEntityDescription(
key=key,
device_class=ENTITY_DEVICE_CLASS_MAP.get(map_key, None),
device_class=ENTITY_SENSOR_DEVICE_CLASS_MAP.get(map_key, None),
entity_category=ENTITY_CATEGORY.get(map_key, None),
translation_key=camel_to_snake(map_key),
icon=ENTITY_ICON.get(map_key, None),
Expand Down Expand Up @@ -148,7 +147,7 @@ def create_mixer_sensor_entity_description(
icon=ENTITY_ICON.get(map_key, None),
native_unit_of_measurement=ENTITY_UNIT_MAP.get(map_key, None),
state_class=STATE_CLASS_MAP.get(map_key, None),
device_class=ENTITY_DEVICE_CLASS_MAP.get(map_key, None),
device_class=ENTITY_SENSOR_DEVICE_CLASS_MAP.get(map_key, None),
suggested_display_precision=ENTITY_PRECISION.get(map_key, 0),
process_val=ENTITY_VALUE_PROCESSOR.get(map_key, lambda x: x),
)
Expand Down

0 comments on commit 2017ce2

Please sign in to comment.