pvvx / ZigbeeTLc

Custom firmware for Zigbee 3.0 IoT devices on the TLSR825x chip
Other
327 stars 15 forks source link

ZHA patch for more precision display of data for all Zigbee devices. #6

Open pvvx opened 8 months ago

pvvx commented 8 months ago

ZHA patch for more precision display of data for all Zigbee devices.

Find the file components/zha/sensor.py (base path ~/.lib64/python3.xx/site-packages/homeassistant) and fix it:

class Sensor(ZhaEntity, SensorEntity):
    """Base ZHA sensor."""

    _attribute_name: int | str | None = None
    _decimals: int = 2
    _divisor: int = 1
    _multiplier: int | float = 1
        """Return the state of the entity."""
        # per zcl specs battery percent is reported at 200% ¯\_(ツ)_/¯
        if not isinstance(value, numbers.Number) or value == -1:
            return None
        value = round(value / 2, 1)
        return value

site-packages/homeassistant/components/zha/core/cluster_handlers/general.py :


class DeviceTemperature(ClusterHandler):
    """Device Temperature cluster handler."""

    REPORT_CONFIG = (
        {
            "attr": "current_temperature",
            "config": (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 10),
        },
    )

site-packages/homeassistant/components/zha/core/cluster_handlers/measurement.py :


class RelativeHumidity(ClusterHandler):
    """Relative Humidity measurement cluster handler."""

    REPORT_CONFIG = (
        AttrReportConfig(
            attr="measured_value",
            config=(REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 50),
        ),
    )

...

class TemperatureMeasurement(ClusterHandler):
    """Temperature measurement cluster handler."""

    REPORT_CONFIG = (
        AttrReportConfig(
            attr="measured_value",
            config=(REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 10),
        ),
    )

site-packages/homeassistant/components/zha/core/const.py :

REPORT_CONFIG_ATTR_PER_REQ = 3
REPORT_CONFIG_MAX_INT = 180
REPORT_CONFIG_MAX_INT_BATTERY_SAVE = 10800
REPORT_CONFIG_MIN_INT = 30
REPORT_CONFIG_MIN_INT_ASAP = 1

image

image

image

image


https://community.home-assistant.io/t/provide-higher-precision-temperature-value-unrounded-values/502245