diff --git a/homeassistant/components/shelly/const.py b/homeassistant/components/shelly/const.py index 89820a289ed..401b8131487 100644 --- a/homeassistant/components/shelly/const.py +++ b/homeassistant/components/shelly/const.py @@ -158,9 +158,6 @@ KELVIN_MIN_VALUE_COLOR: Final = 3000 UPTIME_DEVIATION: Final = 5 -# Max RPC switch/input key instances -MAX_RPC_KEY_INSTANCES = 4 - # Time to wait before reloading entry upon device config change ENTRY_RELOAD_COOLDOWN = 60 diff --git a/homeassistant/components/shelly/sensor.py b/homeassistant/components/shelly/sensor.py index 3fabf69ad54..b4516b098a2 100644 --- a/homeassistant/components/shelly/sensor.py +++ b/homeassistant/components/shelly/sensor.py @@ -348,7 +348,7 @@ RPC_SENSORS: Final = { "temperature": RpcSensorDescription( key="switch", sub_key="temperature", - name="Temperature", + name="Device Temperature", native_unit_of_measurement=TEMP_CELSIUS, value=lambda status, _: round(status["tC"], 1), device_class=SensorDeviceClass.TEMPERATURE, @@ -358,7 +358,7 @@ RPC_SENSORS: Final = { use_polling_coordinator=True, ), "temperature_0": RpcSensorDescription( - key="temperature:0", + key="temperature", sub_key="tC", name="Temperature", native_unit_of_measurement=TEMP_CELSIUS, @@ -389,7 +389,7 @@ RPC_SENSORS: Final = { use_polling_coordinator=True, ), "humidity_0": RpcSensorDescription( - key="humidity:0", + key="humidity", sub_key="rh", name="Humidity", native_unit_of_measurement=PERCENTAGE, @@ -410,6 +410,26 @@ RPC_SENSORS: Final = { entity_registry_enabled_default=True, entity_category=EntityCategory.DIAGNOSTIC, ), + "voltmeter": RpcSensorDescription( + key="voltmeter", + sub_key="voltage", + name="Voltmeter", + native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, + value=lambda status, _: round(float(status), 2), + device_class=SensorDeviceClass.VOLTAGE, + state_class=SensorStateClass.MEASUREMENT, + entity_registry_enabled_default=True, + available=lambda status: status is not None, + ), + "analoginput": RpcSensorDescription( + key="analoginput", + sub_key="percent", + name="Analog Input", + native_unit_of_measurement=PERCENTAGE, + device_class=SensorDeviceClass.BATTERY, + state_class=SensorStateClass.MEASUREMENT, + entity_registry_enabled_default=True, + ), } diff --git a/homeassistant/components/shelly/utils.py b/homeassistant/components/shelly/utils.py index 7eeb93f2918..985935b3939 100644 --- a/homeassistant/components/shelly/utils.py +++ b/homeassistant/components/shelly/utils.py @@ -21,7 +21,6 @@ from .const import ( DEFAULT_COAP_PORT, DOMAIN, LOGGER, - MAX_RPC_KEY_INSTANCES, RPC_INPUTS_EVENTS_TYPES, SHBTN_INPUTS_EVENTS_TYPES, SHBTN_MODELS, @@ -303,28 +302,12 @@ def get_rpc_key_instances(keys_dict: dict[str, Any], key: str) -> list[str]: if key == "switch" and "cover:0" in keys_dict: key = "cover" - keys_list: list[str] = [] - for i in range(MAX_RPC_KEY_INSTANCES): - key_inst = f"{key}:{i}" - if key_inst not in keys_dict: - return keys_list - - keys_list.append(key_inst) - - return keys_list + return [k for k in keys_dict if k.startswith(key)] def get_rpc_key_ids(keys_dict: dict[str, Any], key: str) -> list[int]: """Return list of key ids for RPC device from a dict.""" - key_ids: list[int] = [] - for i in range(MAX_RPC_KEY_INSTANCES): - key_inst = f"{key}:{i}" - if key_inst not in keys_dict: - return key_ids - - key_ids.append(i) - - return key_ids + return [int(k.split(":")[1]) for k in keys_dict if k.startswith(key)] def is_rpc_momentary_input(