Skip to content

Commit

Permalink
Remove unnecessary async (#77)
Browse files Browse the repository at this point in the history
- Remove unnecessary async
- Removed unused helper
  • Loading branch information
SukramJ authored Dec 21, 2021
1 parent a82f587 commit 784e85e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
6 changes: 5 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
Version 0.1.0 (2021-12-xx)
Version 0.1.x (2021-12-xx)
- Remove unnecessary async
- Removed unused helper

Version 0.1.0 (2021-12-20)
- Bump version to 0.1.0
- Remove interface_id from get_entity_name and get_custom_entity_name
- Add initial test
Expand Down
14 changes: 3 additions & 11 deletions hahomematic/central_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ async def stop(self) -> None:
To stop the central_unit we de-init from the CCU / Homegear,
"""
_LOGGER.info("CentralUnit.stop: Stop connection checker.")
await self.stop_connection_checker()
self.stop_connection_checker()
for name, client in self.clients.items():
if await client.proxy_de_init():
_LOGGER.info("CentralUnit.stop: Proxy de-initialized: %s", name)
Expand All @@ -204,19 +204,11 @@ async def stop(self) -> None:
# un-register this instance from XMLRPCServer
self._xml_rpc_server.un_register_central(self)
# un-register and stop XMLRPCServer, if possible
await xml_rpc.un_register_xml_rpc_server()
xml_rpc.un_register_xml_rpc_server()

_LOGGER.debug("CentralUnit.stop: Removing instance")
del INSTANCES[self.instance_name]

def create_task(self, target: Awaitable) -> None:
"""Add task to the executor pool."""
self.loop.call_soon_threadsafe(self.async_create_task, target)

def async_create_task(self, target: Awaitable) -> asyncio.Task:
"""Create a task from within the event loop. This method must be run in the event loop."""
return self.loop.create_task(target)

def run_coroutine(self, coro: Coroutine) -> Any:
"""call coroutine from sync"""
return asyncio.run_coroutine_threadsafe(coro, self.loop).result()
Expand All @@ -232,7 +224,7 @@ def start_connection_checker(self) -> None:
if self.model is not BACKEND_PYDEVCCU:
self._connection_checker.start()

async def stop_connection_checker(self) -> None:
def stop_connection_checker(self) -> None:
"""Start the connection checker."""
self._connection_checker.stop()

Expand Down
6 changes: 3 additions & 3 deletions hahomematic/xml_rpc_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def run(self) -> None:
)
self.simple_xml_rpc_server.serve_forever()

async def stop(self) -> None:
def stop(self) -> None:
"""Stops the XMLRPCServer."""
_LOGGER.info("XMLRPCServer.stop: Shutting down XMLRPCServer")
self.simple_xml_rpc_server.shutdown()
Expand Down Expand Up @@ -341,12 +341,12 @@ def register_xml_rpc_server(
return xml_rpc


async def un_register_xml_rpc_server() -> bool:
def un_register_xml_rpc_server() -> bool:
"""Unregister the xml rpc server."""
xml_rpc = get_xml_rpc_server()
_LOGGER.info("XMLRPCServer.stop: Shutting down server")
if xml_rpc and xml_rpc.no_central_registered:
await xml_rpc.stop()
xml_rpc.stop()
_set_xml_rpc_server(None)
_LOGGER.info("XMLRPCServer.stop: Server stopped")
return True
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def readme():
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Home Automation",
],
)

0 comments on commit 784e85e

Please sign in to comment.