Skip to content

Commit cc76e6f

Browse files
authored
Merge pull request #28 from fboundy/patch
[codex] Gate optional controls and format version sensors
2 parents 2bf25ec + a61e2e7 commit cc76e6f

16 files changed

Lines changed: 379 additions & 227 deletions

‎custom_components/solisconnect/config_flow.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
vol.Required("has_parallel", default=False): bool,
8989
vol.Required("has_battery", default=True): bool,
9090
vol.Required("has_hv_battery", default=False): bool,
91-
vol.Required("has_generator", default=True): bool,
91+
vol.Required("has_generator", default=False): bool,
9292
}
9393

9494
# Combined schema that accepts both TCP and Serial fields (all optional except connection_type)
@@ -142,7 +142,7 @@
142142
vol.Required("has_parallel", default=False): bool,
143143
vol.Required("has_battery", default=True): bool,
144144
vol.Required("has_hv_battery", default=False): bool,
145-
vol.Required("has_generator", default=True): bool,
145+
vol.Required("has_generator", default=False): bool,
146146
}
147147

148148
OPTIONS_SCHEMA = vol.Schema(
@@ -159,7 +159,7 @@
159159
vol.Required("has_parallel", default=False): bool,
160160
vol.Required("has_battery", default=True): bool,
161161
vol.Required("has_hv_battery", default=False): bool,
162-
vol.Required("has_generator", default=True): bool,
162+
vol.Required("has_generator", default=False): bool,
163163
}
164164
)
165165

@@ -675,7 +675,7 @@ def async_get_options_flow(config_entry):
675675
vol.Required("has_parallel", default=False): bool,
676676
vol.Required("has_battery", default=True): bool,
677677
vol.Required("has_hv_battery", default=False): bool,
678-
vol.Required("has_generator", default=True): bool,
678+
vol.Required("has_generator", default=False): bool,
679679
}
680680
)
681681

‎custom_components/solisconnect/data/solis_config.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def inverter_options_from_config(config: dict, template: InverterConfig) -> Inve
9090
pv=config.get("has_pv", template.type in (InverterType.HYBRID, InverterType.GRID, InverterType.WAVESHARE)),
9191
ac_coupling=config.get("has_ac_coupling", False),
9292
parallel=config.get("has_parallel", False),
93-
generator=config.get("has_generator", True),
93+
generator=config.get("has_generator", False),
9494
battery=config.get("has_battery", True),
9595
hv_battery=config.get("has_hv_battery", False),
9696
)

‎custom_components/solisconnect/sensor_data/hybrid_sensors.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@
3333
"category": Category.BASIC_INFORMATION,
3434
"register": ["33001"],
3535
"multiplier": 0,
36+
"value_format": "hex",
3637
},
3738
{
3839
"name": "HMI Version",
3940
"unique": "solisconnect_inverter_hmi_version",
4041
"category": Category.BASIC_INFORMATION,
4142
"register": ["33002"],
4243
"multiplier": 0,
44+
"value_format": "hex",
4345
},
4446
{
4547
"name": "Protocol Version",

‎custom_components/solisconnect/sensor_data/switch_sensors.py‎

Lines changed: 199 additions & 176 deletions
Large diffs are not rendered by default.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from homeassistant.helpers.entity import EntityCategory
2+
3+
from custom_components.solisconnect.data.enums import Category
4+
5+
SETTING_CATEGORIES = {
6+
Category.BASIC_SETTING,
7+
Category.BATTERY_SETTING,
8+
Category.AC_PORT_SETTING,
9+
Category.GRID_CODE_SETTING,
10+
Category.POWER_CONTROL_SETTING,
11+
Category.FUNCTIONAL_SETTING,
12+
Category.HYBRID_MODE_SETTING,
13+
Category.BACKUP_PORT_SETTING,
14+
Category.REMOTE_CONTROL_SETTING,
15+
Category.SMART_PORT_SETTING,
16+
Category.GENERATOR_SETTING,
17+
Category.HISTORY_DATA_QUERY_SETTING,
18+
Category.REMOTE_DISPATCH_SETTING,
19+
}
20+
21+
22+
def entity_category_for_sensor_category(category: Category | None) -> EntityCategory | None:
23+
if category in SETTING_CATEGORIES:
24+
return EntityCategory.CONFIG
25+
return None

‎custom_components/solisconnect/sensors/solis_base_sensor.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def __init__(
5252
identification=None,
5353
poll_speed=PollSpeed.NORMAL,
5454
data_type: str | None = None,
55+
value_format: str | None = None,
5556
):
5657
"""
5758
:param name: Sensor name
@@ -90,6 +91,7 @@ def __init__(
9091
self.poll_speed = poll_speed
9192
self.category = category
9293
self.identification = identification
94+
self.value_format = value_format
9395

9496
self.dynamic_adjustments()
9597

@@ -169,7 +171,9 @@ def _convert_raw_value(self, values: list[int]):
169171
if getattr(self, "data_type", None) == DataType.S16.value and raw > 32767:
170172
raw -= 65536
171173

172-
if self.multiplier == 0 or self.multiplier == 1:
174+
if self.value_format == "hex":
175+
n_value = f"0x{raw & 0xFFFF:04X}"
176+
elif self.multiplier == 0 or self.multiplier == 1:
173177
n_value = round(raw)
174178
else:
175179
n_value = raw * self.multiplier
@@ -229,6 +233,7 @@ def __init__(self, hass, definition, controller, identification=None):
229233
default=entity.get("default", 0),
230234
multiplier=entity.get("multiplier", 1),
231235
data_type=entity.get("data_type", None),
236+
value_format=entity.get("value_format", None),
232237
unique_id=unique_id_generator(controller, entity),
233238
poll_speed=definition.get("poll_speed", PollSpeed.NORMAL),
234239
),

‎custom_components/solisconnect/sensors/solis_binary_sensor.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from homeassistant.components.switch import SwitchEntity
55
from homeassistant.core import callback
66
from homeassistant.helpers.dispatcher import async_dispatcher_connect
7+
from homeassistant.helpers.entity import EntityCategory
78
from homeassistant.helpers.restore_state import RestoreEntity
89

910
from custom_components.solisconnect import ModbusController
@@ -36,6 +37,7 @@ def __init__(self, hass, modbus_controller, entity_definition):
3637
self._attr_unique_id = unique_id_generator_binary(modbus_controller, self._register, self._bit_position, self._on_value)
3738
self._attr_name = entity_definition["name"]
3839
self._attr_available = False
40+
self._attr_entity_category = EntityCategory.CONFIG
3941

4042
async def async_added_to_hass(self) -> None:
4143
"""Called when entity is added to HA."""

‎custom_components/solisconnect/sensors/solis_number_sensor.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from custom_components.solisconnect.const import REGISTER, VALUE
88
from custom_components.solisconnect.helpers import cache_get, is_correct_controller, register_update_signal
9+
from custom_components.solisconnect.sensors.entity_category import entity_category_for_sensor_category
910
from custom_components.solisconnect.sensors.solis_base_sensor import SolisBaseSensor
1011

1112
_LOGGER = logging.getLogger(__name__)
@@ -43,6 +44,7 @@ def __init__(self, hass, sensor: SolisBaseSensor):
4344
self._attr_state_class = sensor.state_class
4445
self._attr_native_unit_of_measurement = sensor.unit_of_measurement
4546
self._attr_available = not sensor.hidden and sensor.enabled
47+
self._attr_entity_category = entity_category_for_sensor_category(getattr(sensor, "category", None))
4648

4749
self._received_values = {}
4850

‎custom_components/solisconnect/sensors/solis_select_entity.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22

33
from homeassistant.components.select import SelectEntity
4+
from homeassistant.helpers.entity import EntityCategory
45
from homeassistant.helpers.restore_state import RestoreEntity
56

67
from custom_components.solisconnect import ModbusController
@@ -16,6 +17,7 @@ def __init__(self, hass, modbus_controller, entity_definition) -> None:
1617
self._register = entity_definition["register"]
1718
self._attr_name = entity_definition["name"]
1819
self._attr_unique_id = unique_id_generator(modbus_controller, entity_definition["register"], "select")
20+
self._attr_entity_category = EntityCategory.CONFIG
1921

2022
self._attr_options = [e["name"] for e in entity_definition["entities"]]
2123
self._attr_options_raw = entity_definition["entities"]

‎custom_components/solisconnect/sensors/solis_sensor.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from custom_components.solisconnect.const import REGISTER, VALUE
99
from custom_components.solisconnect.data.enums import InverterType, PollSpeed
1010
from custom_components.solisconnect.helpers import cache_get, is_correct_controller, register_update_signal
11+
from custom_components.solisconnect.sensors.entity_category import entity_category_for_sensor_category
1112
from custom_components.solisconnect.sensors.solis_base_sensor import SolisBaseSensor
1213

1314
_LOGGER = logging.getLogger(__name__)
@@ -34,6 +35,7 @@ def __init__(self, hass: HomeAssistant, sensor: SolisBaseSensor):
3435
self._attr_native_unit_of_measurement = sensor.unit_of_measurement
3536
self._attr_available = not sensor.hidden and sensor.enabled
3637
self._attr_suggested_display_precision = self.decimal_count(sensor.multiplier)
38+
self._attr_entity_category = entity_category_for_sensor_category(getattr(sensor, "category", None))
3739

3840
self.is_added_to_hass = False
3941
self._state = None

0 commit comments

Comments
 (0)