mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
Revert "shelly_naming" rebase errors (#43134)
This commit is contained in:
parent
bbd7402793
commit
ad06b6b340
@ -4,7 +4,6 @@ from typing import Any, Callable, Optional, Union
|
||||
|
||||
import aioshelly
|
||||
|
||||
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import device_registry, entity, update_coordinator
|
||||
|
||||
@ -13,53 +12,6 @@ from .const import COAP, DATA_CONFIG_ENTRY, DOMAIN, REST
|
||||
from .utils import get_entity_name, get_rest_value_from_path
|
||||
|
||||
|
||||
def temperature_unit(block_info: dict) -> str:
|
||||
"""Detect temperature unit."""
|
||||
if block_info[aioshelly.BLOCK_VALUE_UNIT] == "F":
|
||||
return TEMP_FAHRENHEIT
|
||||
return TEMP_CELSIUS
|
||||
|
||||
|
||||
def shelly_naming(self, block, entity_type: str):
|
||||
"""Naming for switch and sensors."""
|
||||
|
||||
entity_name = self.wrapper.name
|
||||
if not block:
|
||||
return f"{entity_name} {self.description.name}"
|
||||
|
||||
channels = 0
|
||||
mode = block.type + "s"
|
||||
if "num_outputs" in self.wrapper.device.shelly:
|
||||
channels = self.wrapper.device.shelly["num_outputs"]
|
||||
if (
|
||||
self.wrapper.model in ["SHSW-21", "SHSW-25"]
|
||||
and self.wrapper.device.settings["mode"] == "roller"
|
||||
):
|
||||
channels = 1
|
||||
if block.type == "emeter" and "num_emeters" in self.wrapper.device.shelly:
|
||||
channels = self.wrapper.device.shelly["num_emeters"]
|
||||
if channels > 1 and block.type != "device":
|
||||
# Shelly EM (SHEM) with firmware v1.8.1 doesn't have "name" key; will be fixed in next firmware release
|
||||
if "name" in self.wrapper.device.settings[mode][int(block.channel)]:
|
||||
entity_name = self.wrapper.device.settings[mode][int(block.channel)]["name"]
|
||||
else:
|
||||
entity_name = None
|
||||
if not entity_name:
|
||||
if self.wrapper.model == "SHEM-3":
|
||||
base = ord("A")
|
||||
else:
|
||||
base = ord("1")
|
||||
entity_name = f"{self.wrapper.name} channel {chr(int(block.channel)+base)}"
|
||||
|
||||
if entity_type == "switch":
|
||||
return entity_name
|
||||
|
||||
if entity_type == "sensor":
|
||||
return f"{entity_name} {self.description.name}"
|
||||
|
||||
raise ValueError
|
||||
|
||||
|
||||
async def async_setup_entry_attribute_entities(
|
||||
hass, config_entry, async_add_entities, sensors, sensor_class
|
||||
):
|
||||
@ -218,7 +170,7 @@ class ShellyBlockAttributeEntity(ShellyBlockEntity, entity.Entity):
|
||||
|
||||
self._unit = unit
|
||||
self._unique_id = f"{super().unique_id}-{self.attribute}"
|
||||
self._name = shelly_naming(self, block, "sensor")
|
||||
self._name = get_entity_name(wrapper, block, self.description.name)
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
@ -291,7 +243,7 @@ class ShellyRestAttributeEntity(update_coordinator.CoordinatorEntity):
|
||||
self.description = description
|
||||
|
||||
self._unit = self.description.unit
|
||||
self._name = shelly_naming(self, None, "sensor")
|
||||
self._name = get_entity_name(wrapper, None, self.description.name)
|
||||
self.path = self.description.path
|
||||
self._attributes = self.description.attributes
|
||||
|
||||
|
@ -43,34 +43,37 @@ def get_entity_name(
|
||||
"""Naming for switch and sensors."""
|
||||
entity_name = wrapper.name
|
||||
|
||||
channels = None
|
||||
if block.type == "input":
|
||||
channels = wrapper.device.shelly.get("num_inputs")
|
||||
elif block.type == "emeter":
|
||||
channels = wrapper.device.shelly.get("num_emeters")
|
||||
elif block.type in ["relay", "light"]:
|
||||
channels = wrapper.device.shelly.get("num_outputs")
|
||||
elif block.type in ["roller", "device"]:
|
||||
channels = 1
|
||||
if block:
|
||||
channels = None
|
||||
if block.type == "input":
|
||||
channels = wrapper.device.shelly.get("num_inputs")
|
||||
elif block.type == "emeter":
|
||||
channels = wrapper.device.shelly.get("num_emeters")
|
||||
elif block.type in ["relay", "light"]:
|
||||
channels = wrapper.device.shelly.get("num_outputs")
|
||||
elif block.type in ["roller", "device"]:
|
||||
channels = 1
|
||||
|
||||
channels = channels or 1
|
||||
channels = channels or 1
|
||||
|
||||
if channels > 1 and block.type != "device":
|
||||
entity_name = None
|
||||
mode = block.type + "s"
|
||||
if mode in wrapper.device.settings:
|
||||
entity_name = wrapper.device.settings[mode][int(block.channel)].get("name")
|
||||
if channels > 1 and block.type != "device":
|
||||
entity_name = None
|
||||
mode = block.type + "s"
|
||||
if mode in wrapper.device.settings:
|
||||
entity_name = wrapper.device.settings[mode][int(block.channel)].get(
|
||||
"name"
|
||||
)
|
||||
|
||||
if not entity_name:
|
||||
if wrapper.model == "SHEM-3":
|
||||
base = ord("A")
|
||||
else:
|
||||
base = ord("1")
|
||||
entity_name = f"{wrapper.name} channel {chr(int(block.channel)+base)}"
|
||||
if not entity_name:
|
||||
if wrapper.model == "SHEM-3":
|
||||
base = ord("A")
|
||||
else:
|
||||
base = ord("1")
|
||||
entity_name = f"{wrapper.name} channel {chr(int(block.channel)+base)}"
|
||||
|
||||
# Shelly Dimmer has two input channels and missing "num_inputs"
|
||||
if wrapper.model in ["SHDM-1", "SHDM-2"] and block.type == "input":
|
||||
entity_name = f"{entity_name} channel {int(block.channel)+1}"
|
||||
# Shelly Dimmer has two input channels and missing "num_inputs"
|
||||
if wrapper.model in ["SHDM-1", "SHDM-2"] and block.type == "input":
|
||||
entity_name = f"{entity_name} channel {int(block.channel)+1}"
|
||||
|
||||
if description:
|
||||
entity_name = f"{entity_name} {description}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user