Skip to content

Commit d0dc259

Browse files
committed
Patch Update
1 parent db92896 commit d0dc259

File tree

10 files changed

+155
-190
lines changed

10 files changed

+155
-190
lines changed

custom_components/kocom_wallpad/binary_sensor.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@
1515

1616
from .pywallpad.const import STATE, CODE, TIME
1717
from .pywallpad.enums import DeviceType
18-
from .pywallpad.packet import (
19-
KocomPacket,
20-
ThermostatPacket,
21-
FanPacket,
22-
MotionPacket,
23-
DoorPhonePacket,
24-
)
18+
from .pywallpad.packet import KocomPacket
2519

2620
from .gateway import KocomGateway
2721
from .entity import KocomEntity
@@ -39,8 +33,7 @@ async def async_setup_entry(
3933
@callback
4034
def async_add_binary_sensor(packet: KocomPacket) -> None:
4135
"""Add new binary sensor entity."""
42-
if isinstance(packet, (ThermostatPacket, FanPacket, MotionPacket, DoorPhonePacket)):
43-
async_add_entities([KocomBinarySensorEntity(gateway, packet)])
36+
async_add_entities([KocomBinarySensorEntity(gateway, packet)])
4437

4538
for entity in gateway.get_entities(Platform.BINARY_SENSOR):
4639
async_add_binary_sensor(entity)

custom_components/kocom_wallpad/const.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
BRAND_NAME = "Kocom"
2828
MANUFACTURER = "KOCOM Co., Ltd"
2929
MODEL = "Smart Wallpad"
30-
SW_VERSION = "1.1.0"
30+
SW_VERSION = "1.1.1"
3131

3232
DEVICE_TYPE = "device_type"
3333
ROOM_ID = "room_id"
@@ -48,3 +48,10 @@
4848
EVPacket: Platform.SWITCH,
4949
DoorPhonePacket: Platform.SWITCH,
5050
}
51+
52+
PLATFORM_PACKET_TYPE: tuple[type[KocomPacket], ...] = (
53+
ThermostatPacket,
54+
FanPacket,
55+
EVPacket,
56+
DoorPhonePacket,
57+
)

custom_components/kocom_wallpad/entity.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from __future__ import annotations
44

5-
from homeassistant.const import CONF_UNIQUE_ID
65
from homeassistant.core import callback
76
from homeassistant.helpers.entity import DeviceInfo
87
from homeassistant.helpers.restore_state import RestoreEntity, RestoredExtraData
@@ -49,8 +48,15 @@ def __init__(
4948
DEVICE_TYPE: self.packet._device.device_type,
5049
ROOM_ID: self.packet._device.room_id,
5150
SUB_ID: self.packet._device.sub_id,
52-
CONF_UNIQUE_ID: self.unique_id,
5351
}
52+
self._attr_device_info = DeviceInfo(
53+
identifiers={(DOMAIN, f"{BRAND_NAME}_{self.packet._device.device_type}_{self.gateway.host}".lower())},
54+
manufacturer=MANUFACTURER,
55+
model=MODEL,
56+
name=f"{BRAND_NAME} {process_string(self.packet._device.device_type)}",
57+
sw_version=SW_VERSION,
58+
via_device=(DOMAIN, self.gateway.host),
59+
)
5460

5561
@property
5662
def device_id(self) -> str:
@@ -59,27 +65,13 @@ def device_id(self) -> str:
5965
self.packet._device.device_type,
6066
self.packet._device.room_id,
6167
self.packet._device.sub_id
62-
)
68+
).lower()
6369

6470
@property
6571
def device_name(self) -> str:
6672
"""Return the device name."""
6773
return process_string(self.device_id.replace("_", " "))
6874

69-
@property
70-
def device_info(self) -> DeviceInfo:
71-
"""Return the device information."""
72-
return DeviceInfo(
73-
identifiers={
74-
(DOMAIN, f"{BRAND_NAME}_{self.packet._device.device_type}_{self.gateway.entry.unique_id}".lower())
75-
},
76-
manufacturer=MANUFACTURER,
77-
model=MODEL,
78-
name=f"{BRAND_NAME} {process_string(self.packet._device.device_type)}",
79-
sw_version=SW_VERSION,
80-
via_device=(DOMAIN, self.gateway.entry.unique_id),
81-
)
82-
8375
@property
8476
def available(self) -> bool:
8577
"""Return True if entity is available."""
@@ -88,7 +80,7 @@ def available(self) -> bool:
8880
@callback
8981
def async_handle_packet_update(self, packet: KocomPacket) -> None:
9082
"""Handle packet update."""
91-
if self.packet.packet != packet.packet:
83+
if self.packet._device.state != packet._device.state:
9284
self.packet = packet
9385
self.async_write_ha_state()
9486

@@ -116,4 +108,6 @@ async def send_packet(
116108
self, packet: bytearray | list[tuple[bytearray, float | None]]
117109
) -> None:
118110
"""Send a packet to the gateway."""
111+
if not packet:
112+
return
119113
return await self.gateway.client.send_packet(packet)

custom_components/kocom_wallpad/gateway.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
from homeassistant.helpers.dispatcher import async_dispatcher_send
99
from homeassistant.helpers import entity_registry as er, restore_state
1010

11-
from dataclasses import dataclass
12-
1311
from .pywallpad.client import KocomClient, verify_crc
1412
from .pywallpad.const import (
1513
ERROR,
14+
HOTWATER,
1615
CO2,
1716
TEMPERATURE,
1817
DIRECTION,
@@ -21,17 +20,20 @@
2120
)
2221
from .pywallpad.packet import (
2322
KocomPacket,
24-
ThermostatPacket,
25-
FanPacket,
26-
EVPacket,
27-
DoorPhonePacket,
2823
PacketParser,
2924
DoorPhoneParser,
3025
)
3126

3227
from .connection import RS485Connection
3328
from .util import create_dev_id, decode_base64_to_bytes
34-
from .const import LOGGER, DOMAIN, PACKET_DATA, LAST_DATA, PLATFORM_MAPPING
29+
from .const import (
30+
LOGGER,
31+
DOMAIN,
32+
PACKET_DATA,
33+
LAST_DATA,
34+
PLATFORM_MAPPING,
35+
PLATFORM_PACKET_TYPE,
36+
)
3537

3638

3739
class KocomGateway:
@@ -137,17 +139,18 @@ def parse_platform(self, packet: KocomPacket) -> Platform | None:
137139
LOGGER.warning(f"Unrecognized platform type: {type(packet).__name__}")
138140
return None
139141

140-
platform_packet_types = (ThermostatPacket, FanPacket, EVPacket, DoorPhonePacket)
141-
if isinstance(packet, platform_packet_types) and (sub_id := packet._device.sub_id):
142+
if (isinstance(packet, PLATFORM_PACKET_TYPE) and (sub_id := packet._device.sub_id)):
142143
if ERROR in sub_id:
143144
platform = Platform.BINARY_SENSOR
145+
elif HOTWATER == sub_id:
146+
platform = Platform.SWITCH
144147
elif CO2 in sub_id:
145148
platform = Platform.SENSOR
146149
elif TEMPERATURE in sub_id:
147150
platform = Platform.SENSOR
148151
elif sub_id in {DIRECTION, FLOOR}: # EV
149152
platform = Platform.SENSOR
150-
elif sub_id in RING: # DoorPhone
153+
elif sub_id in RING: # Door Phone
151154
platform = Platform.BINARY_SENSOR
152155

153156
return platform

custom_components/kocom_wallpad/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
"iot_class": "local_push",
1010
"issue_tracker": "https://github.com/lunDreame/kocom-wallpad/issues",
1111
"requirements": [],
12-
"version": "1.1.0"
12+
"version": "1.1.1"
1313
}

custom_components/kocom_wallpad/pywallpad/const.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@
3333
FLOOR = "floor"
3434
RING = "ring"
3535
SHUTDOWN = "shutdown"
36+
ONCE = "once"
37+
ALWAYS = "always"

custom_components/kocom_wallpad/pywallpad/enums.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ class DoorPhoneCommand(IntEnum):
3434
INVOKE = 0x09
3535
CONTROL = 0x0B
3636

37-
class DoorPhoneEntrance(IntEnum):
37+
class DoorPhoneEntrance(StrEnum):
3838
"""Door phone entrance types."""
39-
PRIVATE = 0x02
40-
PUBLIC = 0x08
39+
PRIVATE = "private"
40+
PUBLIC = "public"
4141

4242
class DoorPhoneEventType(IntEnum):
4343
"""Door phone event types."""

0 commit comments

Comments
 (0)