Skip to content

Commit

Permalink
Minor Update
Browse files Browse the repository at this point in the history
  • Loading branch information
lunDreame authored Jan 1, 2025
1 parent 10e0d11 commit 4c42a13
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 78 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ Home Assistant를 위한 Kocom Wallpad 통합구성요소
|-----------|------|-------------------------------|
| 조명 (디밍) | O | |
| 콘센트 | O | |
| 난방 | O | 외출 모드, 난방수/온수 센서, 에러 |
| 난방 | O | 외출 모드, 난방수/온수 센서, 애러 센서 |
| 에어컨 | O | |
| 환기 | O | 프리셋: 환기, 자동, 공기 청정, 에러 |
| 환기 | O | 프리셋: 환기/자동/공기 청정/취침/바이패스, 애러 센서 |
| 가스 | O | 잠금만 지원 |
| 실내 공기질 | O | |
| 모션 | O | 테스트 필요 |
| 도어락 (세대/공동 현관) | X | |
| 엘리베이터 | X | |
| 엘리베이터 | O | |

- **초기 장치 추가 시에는 필이 최초 한번은 장치를 ON/OFF 하셔야 합니다.**
- X의 경우 얼추 코드는 작성되어 있나 구현은 되어 있지 않습니다. 데이터 케이스가 더 필요합니다.
- 장치 추가 등은 이슈 또는 메일로 문의 부탁드립니다.

Expand Down
8 changes: 4 additions & 4 deletions custom_components/kocom_wallpad/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
TARGET_TEMP,
)
from .pywallpad.enums import OpMode, FanMode
from .pywallpad.packet import KocomPacket, ThermostatPacket, AcPacket
from .pywallpad.packet import KocomPacket, ThermostatPacket, ACPacket

from .gateway import KocomGateway
from .entity import KocomEntity
Expand All @@ -48,8 +48,8 @@ def async_add_climate(packet: KocomPacket) -> None:
"""Add new climate entity."""
if isinstance(packet, ThermostatPacket):
async_add_entities([KocomThermostatEntity(gateway, packet)])
elif isinstance(packet, AcPacket):
async_add_entities([KocomAcEntity(gateway, packet)])
elif isinstance(packet, ACPacket):
async_add_entities([KocomACEntity(gateway, packet)])

for entity in gateway.get_entities(Platform.CLIMATE):
async_add_climate(entity)
Expand Down Expand Up @@ -136,7 +136,7 @@ async def async_set_temperature(self, **kwargs) -> None:
await self.send_packet(make_packet)


class KocomAcEntity(KocomEntity, ClimateEntity):
class KocomACEntity(KocomEntity, ClimateEntity):
"""Representation of a Kocom climate."""

_enable_turn_on_off_backwards_compatibility = False
Expand Down
12 changes: 6 additions & 6 deletions custom_components/kocom_wallpad/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
LightPacket,
OutletPacket,
ThermostatPacket,
AcPacket,
ACPacket,
FanPacket,
IAQPacket,
GasPacket,
MotionPacket,
EvPacket,
EVPacket,
)

from homeassistant.const import Platform
Expand All @@ -22,10 +22,10 @@

DEFAULT_PORT = 8899

BRAND_NAME = "kocom"
BRAND_NAME = "Kocom"
MANUFACTURER = "KOCOM Co., Ltd"
MODEL = "Smart Wallpad"
SW_VERSION = "1.0.3"
SW_VERSION = "1.0.4"

DEVICE_TYPE = "device_type"
ROOM_ID = "room_id"
Expand All @@ -37,10 +37,10 @@
LightPacket: Platform.LIGHT,
OutletPacket: Platform.SWITCH,
ThermostatPacket: Platform.CLIMATE,
AcPacket: Platform.CLIMATE,
ACPacket: Platform.CLIMATE,
FanPacket: Platform.FAN,
IAQPacket: Platform.SENSOR,
GasPacket: Platform.SWITCH,
MotionPacket: Platform.BINARY_SENSOR,
EvPacket: Platform.SWITCH,
EVPacket: Platform.SWITCH,
}
27 changes: 20 additions & 7 deletions custom_components/kocom_wallpad/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.restore_state import RestoreEntity, RestoredExtraData
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.util import Throttle

from datetime import timedelta

from .pywallpad.packet import Device, KocomPacket

from .gateway import KocomGateway
from .util import create_dev_id, encode_bytes_to_base64
from .util import process_string, create_dev_id, encode_bytes_to_base64
from .const import (
DOMAIN,
LOGGER,
BRAND_NAME,
MANUFACTURER,
MODEL,
Expand All @@ -23,12 +27,14 @@
PACKET_DATA,
)

MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)


class KocomEntity(RestoreEntity):
"""Base class for Kocom Wallpad entities."""

_attr_has_entity_name = True
_attr_should_poll = False
_attr_should_poll = True

def __init__(
self,
Expand All @@ -42,7 +48,7 @@ def __init__(
self.device_update_signal = f"{DOMAIN}_{self.gateway.host}_{self.device_id}"

self._attr_unique_id = f"{BRAND_NAME}_{self.device_id}-{self.gateway.host}"
self._attr_name = f"{BRAND_NAME} {self.name}"
self._attr_name = f"{BRAND_NAME} {self.device_name}"
self._attr_extra_state_attributes = {
DEVICE_TYPE: self.device.device_type,
ROOM_ID: self.device.room_id,
Expand All @@ -57,9 +63,9 @@ def device_id(self) -> str:
)

@property
def name(self) -> str:
"""Return the name of the entity."""
return self.device_id.replace("_", " ").title()
def device_name(self) -> str:
"""Return the device name."""
return process_string(self.device_id.replace("_", " "))

@property
def device_info(self) -> DeviceInfo:
Expand All @@ -68,7 +74,7 @@ def device_info(self) -> DeviceInfo:
identifiers={(DOMAIN, f"{self.gateway.host}_{self.device.device_type}")},
manufacturer=MANUFACTURER,
model=MODEL,
name=f"{BRAND_NAME.title()} {self.device.device_type}",
name=f"{BRAND_NAME} {process_string(self.device.device_type)}",
sw_version=SW_VERSION,
via_device=(DOMAIN, self.gateway.host),
)
Expand Down Expand Up @@ -100,3 +106,10 @@ def extra_restore_state_data(self) -> RestoredExtraData:
async def send_packet(self, packet: bytes) -> None:
"""Send a packet to the gateway."""
await self.gateway.client.send_packet(packet)

@Throttle(MIN_TIME_BETWEEN_UPDATES)
async def async_update(self) -> None:
"""Update device state."""
if hasattr(self.packet, "make_scan") and callable(self.packet.make_scan):
make_packet = self.packet.make_scan()
await self.send_packet(make_packet)
16 changes: 8 additions & 8 deletions custom_components/kocom_wallpad/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
from dataclasses import dataclass

from .pywallpad.client import KocomClient
from .pywallpad.const import TEMPERATURE, CO2
from .pywallpad.const import ERROR, CO2, TEMPERATURE, DIRECTION, FLOOR
from .pywallpad.packet import (
KocomPacket,
ThermostatPacket,
FanPacket,
EvPacket,
EVPacket,
PacketParser,
)

Expand Down Expand Up @@ -114,15 +114,15 @@ def parse_platform(self, packet: KocomPacket) -> Platform | None:
LOGGER.warning(f"Unrecognized platform type: {type(packet).__name__}")
return None

platform_packet_types = (ThermostatPacket, FanPacket, EvPacket)
platform_packet_types = (ThermostatPacket, FanPacket, EVPacket)
if isinstance(packet, platform_packet_types) and (sub_id := packet._device.sub_id):
if TEMPERATURE in sub_id:
platform = Platform.SENSOR
if ERROR in sub_id:
platform = Platform.BINARY_SENSOR
elif CO2 in sub_id:
platform = Platform.SENSOR
elif "error" in sub_id:
platform = Platform.BINARY_SENSOR
elif "direction" in sub_id:
elif TEMPERATURE in sub_id:
platform = Platform.SENSOR
elif sub_id in {DIRECTION, FLOOR}: # EV
platform = Platform.SENSOR

return platform
Expand Down
2 changes: 1 addition & 1 deletion custom_components/kocom_wallpad/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"iot_class": "local_push",
"issue_tracker": "https://github.com/lunDreame/kocom-wallpad/issues",
"requirements": [],
"version": "1.0.3"
"version": "1.0.4"
}
12 changes: 8 additions & 4 deletions custom_components/kocom_wallpad/pywallpad/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
ERROR_CODE = "error_code"
HOTWATER_TEMP = "hotwater_temp"
HEATWATER_TEMP = "heatwater_temp"
ERROR = "error"

OP_MODE = "op_mode"
FAN_MODE = "fan_mode"
Expand All @@ -27,12 +28,15 @@
PRESET_LIST = "preset_list"
SPEED_LIST = "speed_list"

PM10 = "pm10"
PM25 = "pm25"
CO2 = "co2"
VOC = "voc"
PM10 = "PM10"
PM25 = "PM25"
CO2 = "CO2"
VOC = "VOC"
TEMPERATURE = "temperature"
HUMIDITY = "humidity"

TIME = "time"
DATE = "date"

DIRECTION = "direction"
FLOOR = "floor"
Loading

0 comments on commit 4c42a13

Please sign in to comment.