scottyphillips / pychonet

A simple to use library for interfacing with the ECHONETlite protocol
GNU General Public License v3.0
20 stars 17 forks source link

ROADMAP: Use Machine Readable Index for Pychonet 3.0 #64

Open scottyphillips-work opened 11 months ago

scottyphillips-work commented 11 months ago

The ECHONETLite Machine readable Appendix (MRA) provides a JSON formatted representation of ECHONETLite. In the second major redesign of this library, we could look up the MRA in order to parse data rather then trying to hand code objects all the time. Big job to redesign. But could be very worthwhile and save continued effort. Would also provide a built in JA translation for its natural domestic market. May also work better with Home Assistant.

https://echonet.jp/spec-en/#standard-08

MRA Structure The MRA provides: Definitions.json -> describes the format of echonetlite payloads.

Also provides devices, node-profile and superclassjson files. Payloads also can be described within objects, or in the definitions file.

Other considerations:

One thing I am unsure of is the 'mcrules' files. (From release notes: The files in the folder MCRules are used to generate Device Descriptions for the ECHONET Lite Web API). Think these can be ignored.

Where I think version 3.0 will be different: There will be no more Python objects like 'HomeAirConditioner' etc and no more class-specific getters/setters. This is less of an issue to Home Assistant as it appears. Pychonet 2.0 currently uses class specific getter/setters merely as wrappers to setMessage and could be cleaned up out of the home-assistant custom component in preparation.

Design Changes:

Example flow: 0x01:0x30 Home Air Conditioner. EPC: 0xA0

if type['data'] == 'oneOf':
    value = OneOf(self, edt)

def OneOf(EchonetLite, edt):
  array = EchonetLite.type['data']['oneOf']
  for each array value:
       test EDT against value
       if if value['type'] == state:
            test EDT against enum:
               if enum matches EDT value, return data (eg 0x41 return 'auto')
       if value['type'] == level
             test EDT against value range
             if within range return value. 
       return['unsupported value']
nao-pon commented 11 months ago

I also recently learned about MRA. I also think that this will contribute to greatly reducing maintenance costs in the future. I totally agree with supporting MRA!

ammgws commented 11 months ago

Might be able to get some additional ideas from projects such as https://github.com/banban525/echonetlite2mqtt