Skip to content

Commit

Permalink
Merge pull request #39 from mypal/test
Browse files Browse the repository at this point in the history
兼容网关版本02.10.00
  • Loading branch information
mypal authored Nov 11, 2022
2 parents bb0313e + ba4bb79 commit 6838f05
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 12 deletions.
10 changes: 7 additions & 3 deletions custom_components/ds_air/ds_air_service/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def decoder(b):

def result_factory(data):
r1, length, r2, r3, subbody_ver, r4, cnt, dev_type, dev_id, need_ack, cmd_type, subbody, r5 = data

if dev_id == EnumDevice.SYSTEM.value[1]:
if cmd_type == EnumCmdType.SYS_ACK.value:
result = AckResult(cnt, EnumDevice.SYSTEM)
Expand Down Expand Up @@ -123,7 +122,10 @@ def read(self, l):

def read_utf(self, l):
pos = self._pos
s = self._b[pos:pos + l].decode('utf-8')
try:
s = self._b[pos:pos + l].decode('utf-8')
except UnicodeDecodeError:
s = None
pos += l
self._pos = pos
return s
Expand Down Expand Up @@ -454,11 +456,13 @@ def load_bytes(self, b):
dev = Device()
dev.room_id = room.id
dev.unit_id = unit_id
if ver_flag != 1:
if ver_flag > 2:
length = d.read1()
dev.name = d.read_utf(length)
length = d.read1()
dev.alias = d.read_utf(length)
if dev.alias is None:
dev.alias = room.alias
self.rooms.append(room)

def do(self):
Expand Down
3 changes: 2 additions & 1 deletion custom_components/ds_air/ds_air_service/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def do_connect(self):

def send(self, p: Param):
self._locker.acquire()
_log("send hex: 0x"+p.to_string().hex())
_log('\033[31msend:\033[0m')
_log(display(p))
done = False
Expand Down Expand Up @@ -76,7 +77,7 @@ def recv(self) -> (typing.List[BaseResult], bytes):
time.sleep(3)
self.do_connect()
if data is not None:
_log("hex: 0x"+data.hex())
_log("recv hex: 0x"+data.hex())
while data:
try:
r, b = decoder(data)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/ds_air/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"dependencies": [],
"codeowners": [],
"requirements": [],
"version": "1.3.1",
"version": "1.3.2",
"config_flow": true
}
15 changes: 10 additions & 5 deletions custom_components/ds_air/sensor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Support for Xiaomi Aqara sensors."""
"""Support for Daikin sensors."""
from typing import Optional

from homeassistant.components.sensor import SensorEntity
from homeassistant.components.sensor import SensorEntity, SensorStateClass
from homeassistant.helpers.entity import DeviceInfo

from .const import DOMAIN, SENSOR_TYPES
Expand All @@ -10,7 +10,7 @@


async def async_setup_entry(hass, config_entry, async_add_entities):
"""Perform the setup for Xiaomi devices."""
"""Perform the setup for Daikin devices."""
entities = []
for device in Service.get_sensors():
for key in SENSOR_TYPES:
Expand All @@ -20,10 +20,10 @@ async def async_setup_entry(hass, config_entry, async_add_entities):


class DsSensor(SensorEntity):
"""Representation of a XiaomiSensor."""
"""Representation of a DaikinSensor."""

def __init__(self, device: Sensor, data_key):
"""Initialize the XiaomiSensor."""
"""Initialize the DaikinSensor."""
self._data_key = data_key
self._name = device.alias
self._unique_id = device.unique_id
Expand Down Expand Up @@ -80,6 +80,11 @@ def device_class(self):
if self._data_key in SENSOR_TYPES
else None
)

@property
def state_class(self):
"""Return the state class of this entity."""
return SensorStateClass.MEASUREMENT

@property
def state(self):
Expand Down
21 changes: 19 additions & 2 deletions custom_components/ds_air/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,34 @@
from ds_air_service.decoder import decoder

list = [
'0227000d00000011f4cf2d00000000000001a015000211000d000000020000000000000000000100020303',
# '0212000d000000010000000000000000001000000103',
# '0211000d0000000500000000000000000001000203',
]


def show(s):
if s[0] == 'D':
s = s[6:]
print(s)
b = bytes.fromhex(s)
while b:
r, b = decoder(b)
print(display(r))

for i in list:
show(i)

# show(list[0])
import socket

def connect():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("192.168.1.213", 8008))
s.sendall(bytes.fromhex("0210000d0001000100000000000000000100a003"))
s.sendall(bytes.fromhex("0213000d00010005000000000000000001300001ffff03"))
"0x02 1300 0d00 0100 05000000 000000000001300001ffff03"
"0x02 1300 0d00 0100 02000000 000000000001300001ffff03"
while (True):
data = s.recv(1024)
print("0x"+data.hex())

# connect()

0 comments on commit 6838f05

Please sign in to comment.