mirror of
https://github.com/home-assistant/core.git
synced 2025-05-02 13:17:53 +00:00
Fix type hints in zha smartenergy channel (#73775)
* Fix type hints in zha smartenergy channel * Adjust unit_of_measurement
This commit is contained in:
parent
fb2a3ae135
commit
33a84838b4
@ -122,8 +122,8 @@ class Metering(ZigbeeChannel):
|
|||||||
def __init__(self, cluster: zigpy.zcl.Cluster, ch_pool: ChannelPool) -> None:
|
def __init__(self, cluster: zigpy.zcl.Cluster, ch_pool: ChannelPool) -> None:
|
||||||
"""Initialize Metering."""
|
"""Initialize Metering."""
|
||||||
super().__init__(cluster, ch_pool)
|
super().__init__(cluster, ch_pool)
|
||||||
self._format_spec = None
|
self._format_spec: str | None = None
|
||||||
self._summa_format = None
|
self._summa_format: str | None = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def divisor(self) -> int:
|
def divisor(self) -> int:
|
||||||
@ -131,7 +131,7 @@ class Metering(ZigbeeChannel):
|
|||||||
return self.cluster.get("divisor") or 1
|
return self.cluster.get("divisor") or 1
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_type(self) -> int | None:
|
def device_type(self) -> str | int | None:
|
||||||
"""Return metering device type."""
|
"""Return metering device type."""
|
||||||
dev_type = self.cluster.get("metering_device_type")
|
dev_type = self.cluster.get("metering_device_type")
|
||||||
if dev_type is None:
|
if dev_type is None:
|
||||||
@ -154,7 +154,7 @@ class Metering(ZigbeeChannel):
|
|||||||
return self.DeviceStatusDefault(status)
|
return self.DeviceStatusDefault(status)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self) -> str:
|
def unit_of_measurement(self) -> int:
|
||||||
"""Return unit of measurement."""
|
"""Return unit of measurement."""
|
||||||
return self.cluster.get("unit_of_measure")
|
return self.cluster.get("unit_of_measure")
|
||||||
|
|
||||||
@ -210,18 +210,22 @@ class Metering(ZigbeeChannel):
|
|||||||
|
|
||||||
return f"{{:0{width}.{r_digits}f}}"
|
return f"{{:0{width}.{r_digits}f}}"
|
||||||
|
|
||||||
def _formatter_function(self, selector: FormatSelector, value: int) -> int | float:
|
def _formatter_function(
|
||||||
|
self, selector: FormatSelector, value: int
|
||||||
|
) -> int | float | str:
|
||||||
"""Return formatted value for display."""
|
"""Return formatted value for display."""
|
||||||
value = value * self.multiplier / self.divisor
|
value_float = value * self.multiplier / self.divisor
|
||||||
if self.unit_of_measurement == 0:
|
if self.unit_of_measurement == 0:
|
||||||
# Zigbee spec power unit is kW, but we show the value in W
|
# Zigbee spec power unit is kW, but we show the value in W
|
||||||
value_watt = value * 1000
|
value_watt = value_float * 1000
|
||||||
if value_watt < 100:
|
if value_watt < 100:
|
||||||
return round(value_watt, 1)
|
return round(value_watt, 1)
|
||||||
return round(value_watt)
|
return round(value_watt)
|
||||||
if selector == self.FormatSelector.SUMMATION:
|
if selector == self.FormatSelector.SUMMATION:
|
||||||
return self._summa_format.format(value).lstrip()
|
assert self._summa_format
|
||||||
return self._format_spec.format(value).lstrip()
|
return self._summa_format.format(value_float).lstrip()
|
||||||
|
assert self._format_spec
|
||||||
|
return self._format_spec.format(value_float).lstrip()
|
||||||
|
|
||||||
demand_formatter = partialmethod(_formatter_function, FormatSelector.DEMAND)
|
demand_formatter = partialmethod(_formatter_function, FormatSelector.DEMAND)
|
||||||
summa_formatter = partialmethod(_formatter_function, FormatSelector.SUMMATION)
|
summa_formatter = partialmethod(_formatter_function, FormatSelector.SUMMATION)
|
||||||
|
3
mypy.ini
3
mypy.ini
@ -2997,9 +2997,6 @@ ignore_errors = true
|
|||||||
[mypy-homeassistant.components.zha.core.channels.security]
|
[mypy-homeassistant.components.zha.core.channels.security]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
[mypy-homeassistant.components.zha.core.channels.smartenergy]
|
|
||||||
ignore_errors = true
|
|
||||||
|
|
||||||
[mypy-homeassistant.components.zha.core.device]
|
[mypy-homeassistant.components.zha.core.device]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
|
@ -148,7 +148,6 @@ IGNORED_MODULES: Final[list[str]] = [
|
|||||||
"homeassistant.components.zha.core.channels.homeautomation",
|
"homeassistant.components.zha.core.channels.homeautomation",
|
||||||
"homeassistant.components.zha.core.channels.hvac",
|
"homeassistant.components.zha.core.channels.hvac",
|
||||||
"homeassistant.components.zha.core.channels.security",
|
"homeassistant.components.zha.core.channels.security",
|
||||||
"homeassistant.components.zha.core.channels.smartenergy",
|
|
||||||
"homeassistant.components.zha.core.device",
|
"homeassistant.components.zha.core.device",
|
||||||
"homeassistant.components.zha.core.discovery",
|
"homeassistant.components.zha.core.discovery",
|
||||||
"homeassistant.components.zha.core.gateway",
|
"homeassistant.components.zha.core.gateway",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user