Andre0512 / hon

Home Assistant integration for Haier hOn: support for Haier/Candy/Hoover home appliances like washing machines and air conditioners in 28 languages.
MIT License
1.29k stars 2.47k forks source link

The integration does not show any device #3

Closed jangelgon closed 1 year ago

jangelgon commented 1 year ago

The integration does not show any device and does not show any error, I think it is not able to extract the data from the device or the pyhOn data does not match what is searched for in the integration. I have checked the hon.py file and mac_address on my device with pyhOn shows macAddress. I think that the Candy devices do not show the data in the same way as the Haier ones

This is my pyhOn output:

========== TD - Dryer ========== data: appliance: PK: user#eu-west-1:a6f1822e-beee-44f3-a5bb-5c4cb18b53ad SK: app#8c-4b-14-b3-44-a1 applianceId: 8c-4b-14-b3-44-a1#2022-11-22T19:31:28Z applianceModelId: 497 applianceStatus: 1 applianceTypeId: 8 applianceTypeName: TD attributes: acuVersion: 4.B.0 chipset: ESP32D0WDQ5 dictionaryId: 197 lang: it-IT uiVersion: 3.C.5 brand: candy code: 31102169 connectivity: wifi|ble coords: lat: lng: eepromId: 160 eepromName: 40017062 enrollmentDate: 2022-11-22T19:31:28.443Z firstEnrollment: False firstEnrollmentTBC: False fwVersion: 3.2.5 id: 497 lastUpdate: 2022-11-22T19:31:34Z macAddress: 8c-4b-14-b3-44-a1 modelName: ROE H9A3TCEX-S nickName: Secadora purchaseDate: 2022-11-21T23:00:00.000Z sections: chatbot: True demo: True ecoDelayStart: True inventory: True snap_and_dry: True snap_wash: True serialNumber: 3110216988323391 series: rapido structure: heatpump topics: publish: subscribe:

alexandre-leites commented 1 year ago

Hey,

It is because the only currently supported device type is "WM", and yours is "TD". You will need to edit the sensor files inside your custom components, to add the sensors for TD.

It is pretty straight forward, just look for the py files and look for lines similar to

SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
    "WM": (
            <sensors>
    )

Copy and paste and change to yours type:

SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
    "WM": (
            <sensors>
    ),
    "TD": (
            <sensors>
    ),

You might need to add/remove/modify depending on the functions your machine has.

I am currently testing mine which is WD instead of WM as well.

jangelgon commented 1 year ago

Yes, I have already created that, I think the problem is that it cannot create the main device, which is created with the hon.py file. If you notice it refers to mac_address, nick_name and model_name. This script collects the data macAddress, nickName and modelName. But in the pyhOn output they come out as macAddress, nickName and modelName, from what I've seen.

import logging from datetime import timedelta

from pyhon.device import HonDevice

from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.update_coordinator import CoordinatorEntity from homeassistant.helpers.update_coordinator import DataUpdateCoordinator

from .const import DOMAIN

_LOGGER = logging.getLogger(name)

class HonEntity(CoordinatorEntity): _attr_has_entity_name = True

def __init__(self, hass, entry, coordinator, device: HonDevice) -> None:
    super().__init__(coordinator)

    self._hon = hass.data[DOMAIN][entry.unique_id]
    self._hass = hass
    self._device = device

    self._attr_unique_id = self._device.mac_address

@property
def device_info(self):
    return DeviceInfo(
        identifiers={(DOMAIN, self._device.mac_address)},
        manufacturer=self._device.get("brand", ""),
        name=self._device.nick_name if self._device.nick_name else self._device.model_name,
        model=self._device.model_name,
        sw_version=self._device.get("fwVersion", ""),
    )

class HonCoordinator(DataUpdateCoordinator): def init(self, hass, device: HonDevice): """Initialize my coordinator.""" super().init(hass, _LOGGER, name=device.mac_address, update_interval=timedelta(seconds=30)) self._device = device

async def _async_update_data(self):
    await self._device.update()
jangelgon commented 1 year ago

imagen

Andre0512 commented 1 year ago

Hi, a few very common attributes, which I expected to be available for all devices, are populated additionally as class properties with underscore, see here. But the most attributes are loaded dynamically and can only be accessed as items (see here) or with the get-method (see here), so I think this i not the problem. Mixing snake-case and camel-case is a bit confusing here, but PEP8 recommends to write properties as snake-case and haier uses camel-case for it's api, so I think this is a thing we must live with.

I take a closer look at the code tonight to see if there is any other problem, but at the moment I have no idea what it could be and it should run like described by @alexandre-leites.

Andre0512 commented 1 year ago

Hi, I can see no reason why a device will not be created if any key can be found. Of course many of the washing machine keys will not work with your dryer and will therefore not appear in home assistant (You would have to add the keys yourself that are relevant for your appliance). But the errors-sensor and some other should be displayed if you just replace WM with TD.

Please check if you have really replaced all WM keys with TD in all places (for testing!) and if there really no error message appears in the home assistant logs.

jangelgon commented 1 year ago

Work fine, thanks