Skip to content

Commit

Permalink
Merge pull request #23 from grimmpp/feature-branch
Browse files Browse the repository at this point in the history
bug-fix usb300 detection
  • Loading branch information
grimmpp authored Apr 9, 2024
2 parents 4e522c6 + 48762fb commit f9ca0f9
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 62 deletions.
8 changes: 6 additions & 2 deletions changes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Change Log

## v0.1.7 Bug-Fix missing dependency in v0.1.16
## v0.1.18 Bug-fix for USB300 detection
* Bug-fix USB300 detection
* Typos removed

## v0.1.17 Bug-Fix missing dependency in v0.1.16
* added dependency `esp2_gateway_adapter`

## v0.1.16 Improved send message and program devices (DELETED)
Expand Down Expand Up @@ -35,7 +39,7 @@
* Serial port detection for FAM-USB and USB300 improved.
* TODO: Cleanup of ESP3 communication, move function into lib

## v0.1.8 Wireless Tranceiver Support
## v0.1.8 Wireless Transceiver Support
* Reset suggested HA settings added
* Support for FAM-USB. Is now detected as gateway and contained in HA config
* **Experimental** Support for USB300. CODE CLEANUP HEAVILY NEEDED!!!
Expand Down
14 changes: 7 additions & 7 deletions demo.eodm
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ devices:
ha_platform: ''
key_function: SWITCHING_STATE_FROM_CONTROLLER
memory_entries: *id002
name: HA Contoller FF-86-B0-8A
name: HA Controller FF-86-B0-8A
use_in_ha: false
version: unknown
FF-86-B0-8B: !!python/object:eo_man.data.device.Device
Expand All @@ -135,7 +135,7 @@ devices:
ha_platform: ''
key_function: SWITCHING_STATE_FROM_CONTROLLER
memory_entries: *id002
name: HA Contoller FF-86-B0-8B
name: HA Controller FF-86-B0-8B
use_in_ha: false
version: unknown
FF-86-B0-8C: !!python/object:eo_man.data.device.Device
Expand All @@ -151,7 +151,7 @@ devices:
ha_platform: ''
key_function: SWITCHING_STATE_FROM_CONTROLLER
memory_entries: *id002
name: HA Contoller FF-86-B0-8C
name: HA Controller FF-86-B0-8C
use_in_ha: false
version: unknown
FF-BC-00-00: !!python/object:eo_man.data.device.Device
Expand All @@ -161,7 +161,7 @@ devices:
channel: 1
comment: null
dev_size: 1
device_type: FAM-USB (Wireless Tranceiver)
device_type: FAM-USB (Wireless Transceiver)
external_id: FF-BC-00-00
memory_entries: &id003 []
name: FAM-USB (FF-BC-00-00)
Expand Down Expand Up @@ -704,7 +704,7 @@ devices:
ha_platform: ''
key_function: OPERATIONS_COMMAND_WITH_TIME_VALUE_TRASMISSION_FROM_CONTROLLER
memory_entries: *id002
name: HA Contoller 00-00-B0-05
name: HA Controller 00-00-B0-05
use_in_ha: false
version: unknown
FF-CE-10-87: !!python/object:eo_man.data.device.Device
Expand All @@ -720,7 +720,7 @@ devices:
ha_platform: ''
key_function: SWITCHING_STATE_FROM_CONTROLLER
memory_entries: *id002
name: HA Contoller 00-00-B0-07
name: HA Controller 00-00-B0-07
use_in_ha: false
version: unknown
FF-D6-00-00: !!python/object:eo_man.data.device.Device
Expand All @@ -730,7 +730,7 @@ devices:
channel: 1
comment: null
dev_size: 1
device_type: USB300 (Wireless Tranceiver)
device_type: USB300 (Wireless Transceiver)
external_id: FF-D6-00-00
memory_entries: *id003
name: USB300 (FF-D6-00-00)
Expand Down
2 changes: 1 addition & 1 deletion eo_man/controller/app_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AppBusEventType(Enum):
SET_DATA_TABLE_FILTER = 13 # applies data filter to data table
ADDED_DATA_TABLE_FILTER = 14 # adds data filter to application data
REMOVED_DATA_TABLE_FILTER = 15 # remove data filter from application data
ASYNC_TRANCEIVER_DETECTED = 17 # type:str (FAM-USB), base_id:str 00-00-00-00
ASYNC_TRANSCEIVER_DETECTED = 17 # type:str (FAM-USB), base_id:str 00-00-00-00
SEND_MESSAGE_TEMPLATE_LIST_UPDATED = 18

class AppBus():
Expand Down
36 changes: 18 additions & 18 deletions eo_man/controller/serial_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,22 @@ def _get_gateway2serial_port_mapping(self) -> dict[str:list[str]]:
"""
# python -m serial.tools.miniterm COM10 57600 --encoding hexlify

_ports:list[ListPortInfo] = serial.tools.list_ports.comports()
for p in _ports:
print(f"port: {p.device}, hwid: {p.hwid}")
print(len(_ports), 'ports found')

# if sys.platform.startswith('win'):
# ports = ['COM%s' % (i + 1) for i in range(256)]
# elif sys.platform.startswith('linux') or sys.platform.startswith('cygwin'):
# # this excludes your current terminal "/dev/tty"
# ports = glob.glob('/dev/tty[A-Za-z]*')
# elif sys.platform.startswith('darwin'):
# ports = glob.glob('/dev/tty.*')
# else:
# raise EnvironmentError('Unsupported platform')
# _ports:list[ListPortInfo] = serial.tools.list_ports.comports()
# for p in _ports:
# print(f"port: {p.device}, hwid: {p.hwid}")
# print(len(_ports), 'ports found')

if sys.platform.startswith('win'):
ports = ['COM%s' % (i + 1) for i in range(256)]
elif sys.platform.startswith('linux') or sys.platform.startswith('cygwin'):
# this excludes your current terminal "/dev/tty"
ports = glob.glob('/dev/tty[A-Za-z]*')
elif sys.platform.startswith('darwin'):
ports = glob.glob('/dev/tty.*')
else:
raise EnvironmentError('Unsupported platform')

ports = [p.device for p in _ports if p.vid == self.USB_VENDOR_ID]
# ports = [p.device for p in _ports if p.vid == self.USB_VENDOR_ID]

fam14 = GatewayDeviceType.GatewayEltakoFAM14.value
usb300 = GatewayDeviceType.GatewayEnOceanUSB300.value
Expand Down Expand Up @@ -248,15 +248,15 @@ async def async_create_usb300_device(self):
self.current_base_id = b2s(self._serial_bus.base_id)
self.gateway_id = self.current_base_id

await self.app_bus.async_fire_event(AppBusEventType.ASYNC_TRANCEIVER_DETECTED, {'type': 'USB300',
await self.app_bus.async_fire_event(AppBusEventType.ASYNC_TRANSCEIVER_DETECTED, {'type': 'USB300',
'base_id': self.current_base_id,
'gateway_id': self.gateway_id,
'tcm_version': '',
'api_version': ''})


except Exception as e:
msg = 'Failed to get information about USB300!!!'
msg = 'Failed to get information about USB300 (ESP3)!!!'
self.app_bus.fire_event(AppBusEventType.LOG_MESSAGE, {'msg': msg, 'log-level': 'ERROR', 'color': 'red'})
logging.exception(msg, exc_info=True)
raise e
Expand Down Expand Up @@ -303,7 +303,7 @@ async def async_create_fam_usb_device(self):
tcm_sw_v = '.'.join(str(n) for n in response.body[2:6])
api_v = '.'.join(str(n) for n in response.body[6:10])

await self.app_bus.async_fire_event(AppBusEventType.ASYNC_TRANCEIVER_DETECTED, {'type': 'FAM-USB',
await self.app_bus.async_fire_event(AppBusEventType.ASYNC_TRANSCEIVER_DETECTED, {'type': 'FAM-USB',
'base_id': self.current_base_id,
'gateway_id': self.gateway_id,
'tcm_version': tcm_sw_v,
Expand Down
12 changes: 10 additions & 2 deletions eo_man/data/application_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@ def __init__(self, version:str='unknown',
self.send_message_template_list: list[str] = []


translations:dict[str:str] ={
'name: HA Contoller': 'name: HA Controller',
'(Wireless Tranceiver)': '(Wireless Transceiver)'
}

@classmethod
def read_from_file(cls, filename:str):
result = ApplicationData()

file_content = None
with open(filename, 'rb') as file:
file_content = pickle.load(file)
file_content = pickle.loads(file)

if isinstance(file_content, ApplicationData):
result = file_content
Expand Down Expand Up @@ -70,7 +75,10 @@ def _migrate(cls, obj):
@classmethod
def read_from_yaml_file(cls, filename:str):
with open(filename, 'r') as file:
app_data = yaml.load(file, Loader=yaml.Loader)
file_content = file.read()
for k,v in cls.translations.items():
file_content.replace(k,v)
app_data = yaml.load(file_content, Loader=yaml.Loader)
cls._migrate(app_data)

return app_data
Expand Down
6 changes: 3 additions & 3 deletions eo_man/data/data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, app_bus:AppBus):
self.app_bus.add_event_handler(AppBusEventType.LOAD_FILE, self._reset)
self.app_bus.add_event_handler(AppBusEventType.SET_DATA_TABLE_FILTER, self.set_current_data_filter_handler)
self.app_bus.add_event_handler(AppBusEventType.REMOVED_DATA_TABLE_FILTER, self.remove_current_data_filter_handler)
self.app_bus.add_event_handler(AppBusEventType.ASYNC_TRANCEIVER_DETECTED, self._async_tranceiver_detected)
self.app_bus.add_event_handler(AppBusEventType.ASYNC_TRANSCEIVER_DETECTED, self._async_transceiver_detected)
self.app_bus.add_event_handler(AppBusEventType.SEND_MESSAGE_TEMPLATE_LIST_UPDATED, self.on_update_send_message_template_list)

# devices
Expand Down Expand Up @@ -150,15 +150,15 @@ def _serial_callback_handler(self, data:dict):
self.app_bus.fire_event(AppBusEventType.UPDATE_DEVICE_REPRESENTATION, centralized_device)


async def _async_tranceiver_detected(self, data):
async def _async_transceiver_detected(self, data):
base_id = data['base_id']
if data.get('type', None) is not None:
gw_device = Device(address=base_id,
bus_device=False,
external_id=base_id,
base_id=base_id,
name=f"{data['type']} ({base_id})",
device_type=f"{data['type']} (Wireless Tranceiver)",
device_type=f"{data['type']} (Wireless Transceiver)",
use_in_ha=True
)
if gw_device.external_id not in self.devices:
Expand Down
8 changes: 4 additions & 4 deletions eo_man/data/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ def is_usb300(self) -> bool:
return self.device_type is not None and 'USB300' in self.device_type

def is_gateway(self) -> bool:
return self.is_wired_gateway() or self.is_wireless_tranceiver()
return self.is_wired_gateway() or self.is_wireless_transceiver()

def is_wired_gateway(self) -> bool:
return self.is_fam14() or self.is_fgw14_usb()

def is_wireless_tranceiver(self) -> bool:
return self.is_usb300() or self.is_fam_usb() or (self.device_type is not None and 'Wireless Tranceiver' in self.device_type)
def is_wireless_transceiver(self) -> bool:
return self.is_usb300() or self.is_fam_usb() or (self.device_type is not None and 'Wireless Transceiver' in self.device_type)

def is_bus_device(self) -> bool:
return self.bus_device
Expand Down Expand Up @@ -242,7 +242,7 @@ def get_decentralized_device_by_sensor_info(cls, sensor_info:SensorInfo, base_id
bd.device_type = 'Smart Home'
bd.ha_platform = ''
bd.eep = ''
bd.name = 'HA Contoller ' + sensor_info.sensor_id_str
bd.name = 'HA Controller ' + sensor_info.sensor_id_str
elif 'WEATHER_STATION' in bd.key_function:
bd.use_in_ha = True
bd.device_type = 'Weather Station'
Expand Down
2 changes: 1 addition & 1 deletion eo_man/data/ha_config_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def export_additional_fields(self, gateway:Device, additional_fields:dict, space
spaces = space_count*" " + " "
for key in additional_fields.keys():
value = additional_fields[key]
if parent_key in ['sender'] and key == 'id' and gateway.is_wireless_tranceiver():
if parent_key in ['sender'] and key == 'id' and gateway.is_wireless_transceiver():
value = data_helper.a2s( int("0x"+value[-2:], base=16) + data_helper.a2i(gateway.base_id) )
if isinstance(value, str) or isinstance(value, int):
if key not in [CONF_COMMENT, CONF_REGISTERED_IN]:
Expand Down
4 changes: 2 additions & 2 deletions eo_man/view/serial_communication_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def update_cb_gateways_for_HA(self, event=None):
gateways = []
for d in self.data_manager.devices.values():
if d.is_gateway():
gateways.append(f"{d.device_type.replace(' (Wireless Tranceiver)', '')} ({d.external_id})")
gateways.append(f"{d.device_type.replace(' (Wireless Transceiver)', '')} ({d.external_id})")

self.cb_gateways_for_HA['values'] = gateways
if self.cb_gateways_for_HA.get() == '':
Expand All @@ -112,7 +112,7 @@ def on_device_type_changed(self, event):

def write_ha_senders_to_devices(self):
# get gateways and its base id
baseId = self.cb_gateways_for_HA.get().split(' ')[1].replace('(', '').replace(')', '')
baseId = self.cb_gateways_for_HA.get().split(' ')[-1].replace('(', '').replace(')', '')
g = self.data_manager.devices.get(baseId, None)
if g.is_wired_gateway():
sender_base_id = '00-00-B0-00'
Expand Down
Loading

0 comments on commit f9ca0f9

Please sign in to comment.