mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +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
|
import aioshelly
|
||||||
|
|
||||||
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT
|
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers import device_registry, entity, update_coordinator
|
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
|
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(
|
async def async_setup_entry_attribute_entities(
|
||||||
hass, config_entry, async_add_entities, sensors, sensor_class
|
hass, config_entry, async_add_entities, sensors, sensor_class
|
||||||
):
|
):
|
||||||
@ -218,7 +170,7 @@ class ShellyBlockAttributeEntity(ShellyBlockEntity, entity.Entity):
|
|||||||
|
|
||||||
self._unit = unit
|
self._unit = unit
|
||||||
self._unique_id = f"{super().unique_id}-{self.attribute}"
|
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
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
@ -291,7 +243,7 @@ class ShellyRestAttributeEntity(update_coordinator.CoordinatorEntity):
|
|||||||
self.description = description
|
self.description = description
|
||||||
|
|
||||||
self._unit = self.description.unit
|
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.path = self.description.path
|
||||||
self._attributes = self.description.attributes
|
self._attributes = self.description.attributes
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ def get_entity_name(
|
|||||||
"""Naming for switch and sensors."""
|
"""Naming for switch and sensors."""
|
||||||
entity_name = wrapper.name
|
entity_name = wrapper.name
|
||||||
|
|
||||||
|
if block:
|
||||||
channels = None
|
channels = None
|
||||||
if block.type == "input":
|
if block.type == "input":
|
||||||
channels = wrapper.device.shelly.get("num_inputs")
|
channels = wrapper.device.shelly.get("num_inputs")
|
||||||
@ -59,7 +60,9 @@ def get_entity_name(
|
|||||||
entity_name = None
|
entity_name = None
|
||||||
mode = block.type + "s"
|
mode = block.type + "s"
|
||||||
if mode in wrapper.device.settings:
|
if mode in wrapper.device.settings:
|
||||||
entity_name = wrapper.device.settings[mode][int(block.channel)].get("name")
|
entity_name = wrapper.device.settings[mode][int(block.channel)].get(
|
||||||
|
"name"
|
||||||
|
)
|
||||||
|
|
||||||
if not entity_name:
|
if not entity_name:
|
||||||
if wrapper.model == "SHEM-3":
|
if wrapper.model == "SHEM-3":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user