Skip to content

Commit

Permalink
Merge pull request #27 from grimmpp/feature-branch
Browse files Browse the repository at this point in the history
eep bug fix
  • Loading branch information
grimmpp authored May 16, 2024
2 parents 5bba1cd + bee2689 commit afaf869
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 24 deletions.
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/eo_man",
"args": ["-v"],
"console": "integratedTerminal",
"justMyCode": true
},
Expand Down
5 changes: 5 additions & 0 deletions changes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## v0.1.21 EEP representation bug fixes
* Ignores unknown devices
* Fixed EEP representation in dorp down
* Preparation for FDG14 detection

## v0.1.20 Bug-fix for detection of FSR14_2x

## v0.1.19 Added EEP A5-30-01 and A5-30-03
Expand Down
13 changes: 10 additions & 3 deletions eo_man/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ def cli_argument():
description=
"""EnOcean Device Manager (https://github.com/grimmpp/enocean-device-manager) allows you to managed your EnOcean devices and to generate
Home Assistant Configurations for the Home Assistant Eltako Integration (https://github.com/grimmpp/home-assistant-eltako).""")
p.add_argument('-v', '--verbose', help="Logs all messages.", action='store_true')
p.add_argument('-v', '--verbose', help="Logs all messages.", action='count', default=0)
p.add_argument('-c', "--app_config", help="Filename of stored application configuration. Filename must end with '.eodm'.", default=None)
p.add_argument('-ha', "--ha_config", help="Filename for Home Assistant Configuration for Eltako Integration. By passing the filename it will disable the GUI and only generate the Home Assistant Configuration file.")
return p.parse_args()


def init_logger(app_bus:AppBus, log_level:int=logging.INFO):
def init_logger(app_bus:AppBus, log_level:int=logging.INFO, verbose_level:int=0):
file_handler = RotatingFileHandler(os.path.join(PROJECT_DIR, "enocean-device-manager.log"),
mode='a', maxBytes=10*1024*1024, backupCount=2, encoding=None, delay=0)
stream_handler = logging.StreamHandler()
Expand All @@ -50,6 +50,13 @@ def init_logger(app_bus:AppBus, log_level:int=logging.INFO):
LOGGER.setLevel(log_level)
file_handler.setLevel(logging.DEBUG)
stream_handler.setLevel(log_level)

logging.getLogger('esp2_gateway_adapter').setLevel(logging.INFO)
logging.getLogger('eltakobus.serial').setLevel(logging.INFO)
if verbose_level > 0:
logging.getLogger('esp2_gateway_adapter').setLevel(logging.DEBUG)
elif verbose_level > 1:
logging.getLogger('eltakobus.serial').setLevel(logging.DEBUG)

LOGGER.info("Start Application eo_man")
LOGGER.info(ApplicationInfo.get_app_info_as_str())
Expand All @@ -71,7 +78,7 @@ def main():
# init application message BUS
app_bus = AppBus()

init_logger(app_bus, logging.DEBUG if opts.verbose else logging.INFO)
init_logger(app_bus, logging.DEBUG if opts.verbose > 0 else logging.INFO)

# init DATA MANAGER
data_manager = DataManager(app_bus)
Expand Down
34 changes: 17 additions & 17 deletions eo_man/controller/serial_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def establish_serial_connection(self, serial_port:str, device_type:str) -> None:
if device_type == 'FAM-USB':
baudrate = 9600
elif device_type == 'FAM14':
delay_message = .001
delay_message = 0.001

try:
if not self.is_serial_connection_active():
Expand Down Expand Up @@ -344,26 +344,26 @@ def scan_for_devices(self, force_overwrite:bool=False) -> None:
t = threading.Thread(target=lambda: asyncio.run( self._scan_for_devices_on_bus(force_overwrite) ) )
t.start()

async def create_busobject(self, id: int) -> BusObject:
response = await self._serial_bus.exchange(EltakoDiscoveryRequest(address=id), EltakoDiscoveryReply)

assert id == response.reported_address, "Queried for ID %s, received %s" % (id, prettify(response))

for o in sorted_known_objects:
if response.model.startswith(o.discovery_name) and (o.size is None or o.size == response.reported_size):
return o(response, bus=self._serial_bus)
else:
return BusObject(response, bus=self._serial_bus)

async def enumerate_bus(self) -> Iterator[BusObject]: # type: ignore
"""Search the bus for devices, yield bus objects for every match"""

skip_until = 0

for i in range(1, 256):
try:
self.app_bus.fire_event(AppBusEventType.DEVICE_ITERATION_PROGRESS, i/256.0*100.0)
yield await self.create_busobject(i)
if i > skip_until:
self.app_bus.fire_event(AppBusEventType.DEVICE_ITERATION_PROGRESS, i/256.0*100.0)
bus_object = await create_busobject(bus=self._serial_bus, id=i)
skip_until = i + bus_object.size -1
yield bus_object
except TimeoutError:
continue
except Exception as e:
msg = 'Cannot detect device'
self.app_bus.fire_event(AppBusEventType.LOG_MESSAGE, {'msg': msg, 'log-level': 'ERROR', 'color': 'red'})
logging.exception(msg, exc_info=True)


async def _get_fam14_device_on_bus(self, force_overwrite:bool=False) -> None:
is_locked = False
Expand All @@ -375,7 +375,7 @@ async def _get_fam14_device_on_bus(self, force_overwrite:bool=False) -> None:
is_locked = (await locking.lock_bus(self._serial_bus)) == locking.LOCKED

# first get fam14 and make it know to data manager
fam14:FAM14 = await self.create_busobject(255)
fam14:FAM14 = await create_busobject(bus=self._serial_bus, id=255)
self.current_base_id = await fam14.get_base_id()
self.gateway_id = data_helper.a2s( (await fam14.get_base_id_in_int()) + 0xFF )
self.app_bus.fire_event(AppBusEventType.LOG_MESSAGE, {'msg': f"Found device: {fam14}", 'color':'grey'})
Expand Down Expand Up @@ -405,7 +405,7 @@ async def _scan_for_devices_on_bus(self, force_overwrite:bool=False) -> None:
is_locked = (await locking.lock_bus(self._serial_bus)) == locking.LOCKED

# first get fam14 and make it know to data manager
fam14:FAM14 = await self.create_busobject(255)
fam14:FAM14 = await create_busobject(bus=self._serial_bus, id=255)
logging.debug(colored(f"Found device: {fam14}",'grey'))
await self.app_bus.async_fire_event(AppBusEventType.ASYNC_DEVICE_DETECTED, {'device': fam14, 'fam14': fam14, 'force_overwrite': force_overwrite})

Expand Down Expand Up @@ -470,7 +470,7 @@ async def async_ensure_programmed(self, fam14_base_id_int:int, dev:BusObject, se
update_result = await dev.ensure_programmed(i, sender_address, eep_profile)
retry=0
exception = None
time.sleep(0.2) # delay to avaid buffer overflow
time.sleep(0.2) # delay to avoid buffer overflow

except WriteError as e:
logging.exception(str(e))
Expand Down Expand Up @@ -518,7 +518,7 @@ async def async_write_sender_id_to_devices(self, sender_id_list:dict={}): # 4505
self.app_bus.fire_event(AppBusEventType.LOG_MESSAGE, {'msg': "Start writing Home Assistant sender ids to devices", 'color':'red'})

# first get fam14 and make it know to data manager
fam14:FAM14 = await self.create_busobject(255)
fam14:FAM14 = await create_busobject(bus=self._serial_bus, id=255)
fam14_base_id_int = await fam14.get_base_id_in_int()
fam14_base_id = b2s(await fam14.get_base_id_in_bytes())
msg = f"Update devices on Bus (fam14 base id: {fam14_base_id})"
Expand Down
4 changes: 3 additions & 1 deletion eo_man/data/data_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
{'hw-type': 'FUD14', CONF_EEP: 'A5-38-08', 'sender_eep': 'A5-38-08', CONF_TYPE: Platform.LIGHT, 'PCT14-function-group': 3, 'PCT14-key-function': 32, 'description': 'Central command - gateway', 'address_count': 1},
{'hw-type': 'FUD14_800W', CONF_EEP: 'A5-38-08', 'sender_eep': 'A5-38-08', CONF_TYPE: Platform.LIGHT, 'PCT14-function-group': 3, 'PCT14-key-function': 32, 'description': 'Central command - gateway', 'address_count': 1},

{'hw-type': 'FDG14', CONF_EEP: 'A5-38-08', CONF_TYPE: Platform.LIGHT, 'PCT14-function-group': 1, 'PCT14-key-function': 32, 'description': 'Central command - gateway', 'address_count': 16},

{'hw-type': 'FMZ14', CONF_EEP: 'M5-38-08', 'sender_eep': 'A5-38-08', CONF_TYPE: Platform.LIGHT, 'PCT14-function-group': 1, 'description': 'Eltako relay', 'address_count': 1},
{'hw-type': 'FSR14', CONF_EEP: 'M5-38-08', 'sender_eep': 'A5-38-08', CONF_TYPE: Platform.LIGHT, 'PCT14-function-group': 2, 'PCT14-key-function': 51, 'description': 'Eltako relay', 'address_count': 1},
{'hw-type': 'FSR14_1x', CONF_EEP: 'M5-38-08', 'sender_eep': 'A5-38-08', CONF_TYPE: Platform.LIGHT, 'PCT14-function-group': 2, 'PCT14-key-function': 51, 'description': 'Eltako relay', 'address_count': 1},
Expand Down Expand Up @@ -63,7 +65,7 @@ def get_all_eep_names():
if child not in subclasses:
subclasses.add(child)
work.append(child)
return sorted(set([s.__name__.upper() for s in subclasses if len(s.__name__) == 8 and s.__name__.count('_') == 2]))
return sorted(set([s.__name__.replace('_', '-').upper() for s in subclasses if len(s.__name__) == 8 and s.__name__.count('_') == 2]))

def find_eep_by_name(eep_name:str) -> EEP:
for child in EEP.__subclasses__():
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
aiocoap==0.4.7
eltako14bus==0.0.52
eltako14bus==0.0.53
numpy==1.26.3
pillow==10.2.0
pyserial==3.5
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
with open('LICENSE', encoding="utf-8") as f:
license = f.read()

required = ['eltako14bus==0.0.51', 'requests==2.31.0', 'enocean==0.60.1', 'pyserial', 'pyserial-asyncio', 'aiocoap',
required = ['eltako14bus==0.0.53', 'requests==2.31.0', 'enocean==0.60.1', 'pyserial', 'pyserial-asyncio', 'aiocoap',
'esp2_gateway_adapter==0.1',
# 'homeassistant',
'pyyaml',
Expand All @@ -26,7 +26,7 @@

setup(
name='eo_man',
version='0.1.20',
version='0.1.21',
package_dir={'eo_man':"eo_man"},
# packages=find_packages("./eo-man"),
#package_data={'': ['*.png']},
Expand Down

0 comments on commit afaf869

Please sign in to comment.