Skip to content

Commit 310f58b

Browse files
Merge pull request #13 from scottyphillips/asynchonet
Version 2.0.13 promoted to master.
2 parents 65ba418 + f713193 commit 310f58b

22 files changed

+968
-775
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ v0.2, 07 June 2019 -- Fixed bug when setting fan modes 'medium-low' and 'medium-
1212
v0.2.1, 18 August 2019 -- Changed mode 'dehumidify' to 'dry' for HA compatibility
1313
v0.2.2, 24 Feb 2020 -- Minor update to stop HA crashing if no response is received.
1414
v0.3, 2 March 2020 -- Added in function to measure outdoor temperature
15+
v2.0.9, 5 Sep 2021 -- fixed up factory method and pushed updates
16+
v2.0.13, 13 Sep 2021 -- Bug Fixes, better doco, promote to master

LICENCE.txt

Lines changed: 0 additions & 21 deletions
This file was deleted.

LICENSE.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
The MIT License
2+
3+
Copyright (c) 2018 Scott Phillips
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.
22+
23+
- - -
24+
25+
ECHONET Lite Device Emulator
26+
27+
Copyright 2020 Kanagawa Institute of Technology
28+
29+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
30+
31+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
32+
33+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ The basic boilerplate EchoNetInstance class can be used to provide
1818
raw connectivity to any compatible device but it is up to the developer
1919
to create useful classes. Any ECHONETlite class additions to the library are welcome.
2020

21+
Version 2.0.0 of this libray was rebuilt to use asyncio for better compatability with home assistant.
22+
23+
2124
It is designed to work with Python 3.9.5+
2225

2326
## Instructions
@@ -29,39 +32,63 @@ pip install pychonet
2932
```
3033

3134
## Basic usage
32-
### Discover a list of ECHONETlite instances using:
35+
36+
### Create the ECHONETLite listener service on port 3610:
37+
```python
38+
from aioudp import UDPServer
39+
from pychonet import Factory
40+
from pychonet import ECHONETAPIClient as api
41+
from pychonet import HomeAirConditioner
42+
from pychonet import EchonetInstance
43+
udp = UDPServer()
44+
loop = asyncio.get_event_loop()
45+
udp.run("0.0.0.0", 3610, loop=loop)
46+
server = api(server=udp, loop=loop)
47+
```
48+
49+
### Discover a list of ECHONETlite instances on a particular server:
50+
```python
51+
await server.discover('192.168.1.6')
52+
```
53+
54+
55+
### Populate the propertymap for a particular ECHONETLite instance:
3356
```python
34-
import pychonet as echonet
35-
echonet_instances = echonet.discover()
36-
print(echonet_instances)
37-
[{'netaddr': '192.168.1.6', 'eojgc': 1, 'eojcc': 48, 'eojci': 1, 'group': 'Air conditioner-related device group', 'code': 'Home air conditioner'}]
57+
await server.getAllPropertyMaps('192.168.1.6', 1, 48, 1)
3858
```
59+
### Create a ECHONETLite device using the Factory:
3960

40-
### Create a HVAC ECHONETlite instance
61+
Paramaters include the port listener, and EOJGC, EOJCC, and EOJCI codes.
4162
```python
42-
aircon = echonet.HomeAirConditioner("192.168.1.6")
63+
aircon = Factory("192.168.1.6",server, 1, 48, 1)
64+
```
65+
66+
### OR, create a specific ECHONETLite instance using built in objects:
67+
```python
68+
aircon = HomeAirConditioner("192.168.1.6", server)
69+
```
4370

4471
### Turn HVAC on or off:
4572
```python
46-
aircon.on()
47-
aircon.off()
48-
aircon.getOperationalStatus()
73+
await aircon.on()
74+
await aircon.off()
75+
await aircon.getOperationalStatus()
4976
{'status': 'off'}
5077
```
5178

52-
### Set or Get a HVACs target temperature
79+
### Set or Get a HVACs target temperature:
5380
```python
54-
aircon.setOperationalTemperature(25)
55-
aircon.getOperationalTemperature()
81+
await aircon.setOperationalTemperature(25)
82+
await aircon.getOperationalTemperature()
5683
{'set_temperature': 25}
5784
```
5885

5986
### Set or Get a HVACs mode of operation:
6087
```python
6188
supported modes = 'auto', 'cool', 'heat', 'dry', 'fan_only', 'other'
6289

63-
aircon.setMode('cool')
64-
aircon.getMode()
90+
await aircon.setMode('cool')
91+
await aircon.getMode()
6592
{'mode': 'cool'}
6693
```
6794
### Set or Get a HVACs fan speed:
@@ -70,15 +97,21 @@ Note - your HVAC may not support all fan speeds.
7097
```python
7198
supported modes = 'auto', 'minimum', 'low', 'medium-Low', 'medium', 'medium-high', 'high', 'very high', 'max'
7299

73-
aircon.setFanSpeed('medium-high')
74-
aircon.getFanSpeed()
100+
await aircon.setFanSpeed('medium-high')
101+
await aircon.getFanSpeed()
75102
{'fan_speed': 'medium-high'}
76103
```
77-
### Get HVAC attributes at once:
104+
### Get HVAC attributes at once (Note, the property map must be populated):
78105
```python
79-
aircon.update()
106+
await aircon.update()
80107
{'status': 'On', 'set_temperature': 25, 'fan_speed': 'medium-high', 'room_temperature': 25, 'mode': 'cooling'}
81108
```
109+
110+
### OR grab a specific attribute at once (Note, the property map must be populated):
111+
```python
112+
await aircon.update(0x80)
113+
```
114+
82115
## Using this library with Home Assistant
83116

84117
NOTE: For Home Assistant users there is now a dedicated repo for the related Home Assistant 'Mitsubishi' custom component that makes use of this Python library:

bin/commands

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from aioudp import UDPServer
2+
from pychonet import Factory
3+
from pychonet import ECHONETAPIClient as api
4+
from pychonet import HomeAirConditioner
5+
from pychonet import EchonetInstance
6+
7+
udp = UDPServer()
8+
loop = asyncio.get_event_loop()
9+
udp.run("0.0.0.0",3610, loop=loop)
10+
server = api(server=udp,loop=loop)
11+
await server.discover('192.168.1.6')
12+
await server.getAllPropertyMaps('192.168.1.6',1,48,1)
13+
device = Factory("192.168.1.6",server, 1,48,1)
14+
await device.update([0x80])

example_async.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import asyncio
2+
3+
from aioudp import UDPServer
4+
from pychonet import ECHONETAPIClient as api
5+
6+
# This example will list the properties for all discovered instances on a given host
7+
8+
async def main():
9+
udp = UDPServer()
10+
loop = asyncio.get_event_loop()
11+
udp.run("0.0.0.0", 3610, loop=loop)
12+
server = api(server=udp, loop=loop)
13+
14+
host = '192.168.1.6'
15+
await server.discover(host)
16+
17+
# Timeout after 3 seconds
18+
for x in range(0, 300):
19+
await asyncio.sleep(0.01)
20+
if 'discovered' in list(server._state[host]):
21+
print("ECHONET Node Discovery Successful!")
22+
break
23+
24+
instance_list = []
25+
state = server._state[host]
26+
for eojgc in list(state['instances'].keys()):
27+
for eojcc in list(state['instances'][eojgc].keys()):
28+
for instance in list(state['instances'][eojgc][eojcc].keys()):
29+
print(f"instance is {instance}")
30+
await server.getAllPropertyMaps(host, eojgc, eojcc, instance)
31+
print(f"{host} - ECHONET Instance {eojgc}-{eojcc}-{instance} map attributes discovered!")
32+
getmap = state['instances'][eojgc][eojcc][instance][ENL_GETMAP]
33+
setmap = state['instances'][eojgc][eojcc][instance][ENL_SETMAP]
34+
35+
await server.getIdentificationInformation(host, eojgc, eojcc, instance)
36+
uid = state['instances'][eojgc][eojcc][instance][ENL_UID]
37+
manufacturer = state['instances'][eojgc][eojcc][instance][ENL_MANUFACTURER]
38+
print(f"{host} - ECHONET Instance {eojgc}-{eojcc}-{instance} Identification number discovered!")
39+
instance_list.append({"host":host,"eojgc":eojgc,"eojcc":eojcc,"eojci":instance,"getmap":getmap,"setmap":setmap,"uid":uid,"manufacturer":manufacturer})
40+
41+
print(instance_list)
42+
43+
if __name__ == "__main__":
44+
asyncio.run(main())

example_battery.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

example_hvac.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)