Skip to content

Commit

Permalink
🐛 [2024-04-24] Fix lock statues
Browse files Browse the repository at this point in the history
  • Loading branch information
MapleEve committed Apr 24, 2024
1 parent a8a82a6 commit dd87a08
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 48 deletions.
26 changes: 14 additions & 12 deletions custom_components/lifesmart/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
SUPPORTED_SWTICH_TYPES,
UPDATE_LISTENER,
)

import voluptuous as vol
import sys

sys.setrecursionlimit(100000)
Expand Down Expand Up @@ -146,12 +146,17 @@ async def data_update_handler(msg):
_LOGGER.debug("已生成实体id - 设备号:%s 中枢:%s 设备类型:%s IDX:%s ", str(device_id), str(hub_id),
str(device_type), str(sub_device_key))

_SUPPORTED_DEVICES = {
SUPPORTED_SWTICH_TYPES: SUPPORTED_SUB_SWITCH_TYPES,
BINARY_SENSOR_TYPES: SUPPORTED_SUB_BINARY_SENSORS,
}

if device_type in _SUPPORTED_DEVICES and sub_device_key in _SUPPORTED_DEVICES[device_type]:
if (
device_type in SUPPORTED_SWTICH_TYPES
and sub_device_key in SUPPORTED_SUB_SWITCH_TYPES
):
dispatcher_send(
hass, f"{LIFESMART_SIGNAL_UPDATE_ENTITY}_{entity_id}", data
)
elif (
device_type in BINARY_SENSOR_TYPES
and sub_device_key in SUPPORTED_SUB_BINARY_SENSORS
):
dispatcher_send(
hass, f"{LIFESMART_SIGNAL_UPDATE_ENTITY}_{entity_id}", data
)
Expand Down Expand Up @@ -256,13 +261,11 @@ async def data_update_handler(msg):
attrs["current_temperature"] = data["v"]
hass.states.set(entity_id, nstat, attrs)
elif device_type in LOCK_TYPES:
_idx = sub_device_key
nstat = hass.states.get(entity_id).state
if _idx == "BAT":
if sub_device_key == "BAT":
dispatcher_send(
hass, f"{LIFESMART_SIGNAL_UPDATE_ENTITY}_{entity_id}", data
)
elif _idx == "EVTLO":
elif sub_device_key == "EVTLO":
"""
type%2==1 表示开启;
type%2==0 表示关闭;
Expand Down Expand Up @@ -298,7 +301,6 @@ async def data_update_handler(msg):
dispatcher_send(
hass, f"{LIFESMART_SIGNAL_UPDATE_ENTITY}_{entity_id}", data
)
# hass.states.set(entity_id, nstat, attrs)
_LOGGER.debug("设备状态更新已推送 %s - 设备编号:%s -门锁更新数据:%s ",
str(LIFESMART_SIGNAL_UPDATE_ENTITY),
str(entity_id), str(data))
Expand Down
80 changes: 53 additions & 27 deletions custom_components/lifesmart/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,66 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
exclude_devices = hass.data[DOMAIN][config_entry.entry_id]["exclude_devices"]
exclude_hubs = hass.data[DOMAIN][config_entry.entry_id]["exclude_hubs"]
client = hass.data[DOMAIN][config_entry.entry_id]["client"]

sensor_devices = []
for device in devices:
device_id = device[DEVICE_ID_KEY]
hub_id = device[HUB_ID_KEY]
device_type = device[DEVICE_TYPE_KEY]

# 剔除不需要的中枢和设备
if device_id in exclude_devices or hub_id in exclude_hubs:
if (
device[DEVICE_ID_KEY] in exclude_devices
or device[HUB_ID_KEY] in exclude_hubs
):
continue

# 只处理的类型
device_type = device[DEVICE_TYPE_KEY]

if device_type not in BINARY_SENSOR_TYPES + LOCK_TYPES:
continue

ha_device = LifeSmartDevice(device, client)

for sub_device_key, sub_device_data in device[DEVICE_DATA_KEY].items():
if device_type in GENERIC_CONTROLLER_TYPES and sub_device_key in ["P5", "P6", "P7"]:
sensor = LifeSmartBinarySensor(ha_device, device, sub_device_key, sub_device_data, client)
sensor_devices.append(sensor)
_LOGGER.debug("Adding Hub device: %s", device) # 打印增加的设备信息
elif device_type == LOCK_TYPES and sub_device_key == "EVTLO":
sensor = LifeSmartBinarySensor(ha_device, device, sub_device_key, sub_device_data, client)
sensor_devices.append(sensor)
_LOGGER.debug("Adding Lock device: %s", device) # 打印增加的设备信息
elif device_type in BINARY_SENSOR_TYPES and sub_device_key in ["M", "G", "B", "AXS", "P1"]:
sensor = LifeSmartBinarySensor(ha_device, device, sub_device_key, sub_device_data, client)
sensor_devices.append(sensor)
_LOGGER.debug("Adding Other Binary device: %s", device) # 打印增加的设备信息

ha_device = LifeSmartDevice(
device,
client,
)
for sub_device_key in device[DEVICE_DATA_KEY]:
sub_device_data = device[DEVICE_DATA_KEY][sub_device_key]
if device_type in GENERIC_CONTROLLER_TYPES:
if sub_device_key in [
"P5",
"P6",
"P7",
]:
sensor_devices.append(
LifeSmartBinarySensor(
ha_device,
device,
sub_device_key,
sub_device_data,
client,
)
)
elif device_type in LOCK_TYPES and sub_device_key == "EVTLO":
sensor_devices.append(
LifeSmartBinarySensor(
ha_device,
device,
sub_device_key,
sub_device_data,
client,
)
)
elif device_type in BINARY_SENSOR_TYPES and sub_device_key in [
"M",
"G",
"B",
"AXS",
"P1",
]:
sensor_devices.append(
LifeSmartBinarySensor(
ha_device,
device,
sub_device_key,
sub_device_data,
client,
)
)
async_add_entities(sensor_devices)


Expand Down Expand Up @@ -152,9 +181,6 @@ def __init__(
"unlocking_user": unlock_user,
"device_type": device_type,
"unlocking_success": is_unlock_success,
"last_updated": datetime.datetime.fromtimestamp(
sub_device_data["ts"] / 1000
).strftime("%Y-%m-%d %H:%M:%S"),
}
_LOGGER.debug("Adding lock device: %s", self._attrs) # Log the lock device information
elif device_type in GENERIC_CONTROLLER_TYPES:
Expand Down
10 changes: 1 addition & 9 deletions custom_components/lifesmart/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,7 @@
GAS_SENSOR_TYPES = ["SL_SC_WA ", "SL_SC_CH", "SL_SC_CP", "ELIQ_EM"]
EV_SENSOR_TYPES = ["SL_SC_THL", "SL_SC_BE", "SL_SC_CQ"]
OT_SENSOR_TYPES = ["SL_SC_MHW", "SL_SC_BM", "SL_SC_G", "SL_SC_BG"]
LOCK_TYPES = [
"SL_LK_LS",
"SL_LK_GTM",
"SL_LK_AG",
"SL_LK_SG",
"SL_LK_YL",
"SL_P_BDLK",
"OD_JIUWANLI_LOCK1"
]
LOCK_TYPES = ["SL_LK_LS", "SL_LK_GTM", "SL_LK_AG", "SL_LK_SG", "SL_LK_YL","SL_P_BDLK","OD_JIUWANLI_LOCK1"]
GUARD_SENSOR_TYPES = ["SL_SC_G", "SL_SC_BG"]
DEVICE_WITHOUT_IDXNAME = [
"SL_NATURE",
Expand Down

0 comments on commit dd87a08

Please sign in to comment.