petrleocompel / hikaxpro_hacs

HACS repository of Hikvision Ax Pro integration for home assistant
MIT License
40 stars 4 forks source link

pircam not supported #6

Closed DejanBukovec closed 1 year ago

DejanBukovec commented 1 year ago

Today Im try integration but do not work. Panel stay offline. With gunkutzeybek integration it work normaly... Is possible make integration that if some detector is not supported that it ignore it instead crash?

Log:

2023-02-24 21:29:22.798 WARNING (SyncWorker_2) [custom_components.hikvision_axpro.model] Invalid detector type pircam 2023-02-24 21:29:22.800 WARNING (SyncWorker_2) [custom_components.hikvision_axpro.model] Detector info: {'id': 1, 'name': 'Pisarna', 'status': 'online', 'sensorStatus': 'normal', 'tamperEvident': False, 'shielded': False, 'bypassed': False, 'armed': False, 'isArming': False, 'alarm': False, 'charge': 'normal', 'chargeValue': 100, 'signal': 121, 'temperature': 24, 'subSystemNo': 2, 'linkageSubSystem': [2], 'detectorType': 'pircam', 'model': '0x00012', 'stayAway': False, 'zoneType': 'Instant', 'isViaRepeater': False, 'zoneAttrib': 'wireless', 'version': 'V1.2.0', 'deviceNo': 4, 'abnormalOrNot': False} 2023-02-24 21:29:23.676 ERROR (MainThread) [custom_components.hikvision_axpro] Unexpected error fetching hikvision_axpro data: 'Delay' is not a valid ZoneType Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 239, in _async_refresh self.data = await self._async_update_data() File "/config/custom_components/hikvision_axpro/init.py", line 205, in _async_update_data await self.hass.async_add_executor_job(self._update_data) File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "/config/custom_components/hikvision_axpro/init.py", line 193, in _update_data zone_status = ZonesResponse.from_dict(zone_response) File "/config/custom_components/hikvision_axpro/model.py", line 257, in from_dict zone_list = from_list(ZoneList.from_dict, obj.get("ZoneList")) File "/config/custom_components/hikvision_axpro/model.py", line 29, in from_list return [f(y) for y in x] File "/config/custom_components/hikvision_axpro/model.py", line 29, in return [f(y) for y in x] File "/config/custom_components/hikvision_axpro/model.py", line 241, in from_dict zone = Zone.from_dict(obj.get("Zone")) File "/config/custom_components/hikvision_axpro/model.py", line 180, in from_dict zone_type = ZoneType(obj.get("zoneType")) File "/usr/local/lib/python3.10/enum.py", line 385, in call return cls.new(cls, value) File "/usr/local/lib/python3.10/enum.py", line 710, in new raise ve_exc ValueError: 'Delay' is not a valid ZoneType

DejanBukovec commented 1 year ago

Im modify model.py and add under "class DetectorType(Enum)" new line: WIRELESS_PIR_CAM_DETECTOR = "pircam" So now looks like:

class DetectorType(Enum):
    OTHER = "other"
    PASSIVE_INFRARED_DETECTOR = "passiveInfraredDetector"
    WIRELESS_EXTERNAL_MAGNET_DETECTOR = "wirelessExternalMagnetDetector"
    WIRELESS_TEMPERATURE_HUMIDITY_DETECTOR = "wirelessTemperatureHumidityDetector"
    WIRELESS_GLASS_BREAK_DETECTOR = "wirelessGlassBreakDetector"
    WIRELESS_PIR_AM_CURTAIN_DETECTOR = "wirelessDTAMCurtainDetector"
    MAGNETIC_CONTACT = "magneticContact"
    WIRELESS_PIR_CAM_DETECTOR = "pircam"

and inside "detector_model_to_name" add new line so now looks like:

def detector_model_to_name(model_id: Optional[str]) -> str:
    if model_id == "0x00001":
        return "Passive infrared detector"
    if model_id == "0x00006":
        return "Magnetic contact"
    if model_id == "0x00012":
        return "Wireless PIR CAM detector"
    if model_id == "0x00018":
        return "Glass break detector"
    if model_id == "0x00026":
        return "Wireless temperature humidity detector"
    if model_id == "0x00028":
        return "Wireless external magnet detector"
    if model_id == "0x00032":
        return "Wireless PIR AM curtain detector"
    if model_id is not None:
        return str(model_id)
    return "Unknown"

And now is probably detected because pircam line disapear but Zone Delay error still exist(I need to look Zone definitions).

DejanBukovec commented 1 year ago

Im add "ZoneType" Delay into definition and now looks like:

class ZoneType(Enum):
    FOLLOW = "Follow"
    INSTANT = "Instant"
    DELAY = "Delay"

Now devices are detected.

Please add this changes to next release.

petrleocompel commented 1 year ago

@DejanBukovec I was not receiving notification on email about any issues !! Thank you I will merge all changes. If you would mention me i would get email immediately.