From d393850cea918a897fc437c76a14c380981f908f Mon Sep 17 00:00:00 2001 From: Joao Amaro Date: Thu, 8 Jun 2023 10:30:03 +0100 Subject: [PATCH] @asyncio.coroutine decorator is removed in Python 3.11. Async keyowrd already being used. Changed beautifulsoup parser from html to lxml, avoiding the warning on homeassistant --- README.md | 5 ++++ custom_components/enigma/__init__.py | 2 +- custom_components/enigma/manifest.json | 2 +- custom_components/enigma/media_player.py | 31 +++++++----------------- custom_components/enigma/notify.py | 3 +-- 5 files changed, 17 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index ebbba82..8b9086c 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,10 @@ You must install OpenWebif from your enigma2 image. - 0.2.7 - 1.3.0 +# Discussion: +Follow the enigma2 integration discussion on [Home Assistant community forum][2]. + + # Install: To use the enigma custom component, place the file `enigma` directory from the root of the repositorie in to the folder `~/.homeassistant/custom_components/` where @@ -189,4 +193,5 @@ joao.amaro@gmail.com # References [1]: https://home-assistant.io +[2]: https://community.home-assistant.io/t/enigma2-receivers-integration/44448 diff --git a/custom_components/enigma/__init__.py b/custom_components/enigma/__init__.py index 94edd64..5be5461 100644 --- a/custom_components/enigma/__init__.py +++ b/custom_components/enigma/__init__.py @@ -19,7 +19,7 @@ from homeassistant.helpers.entity import Entity # VERSION -VERSION = '1.4' +VERSION = '1.6' # REQUIREMENTS REQUIREMENTS = ['beautifulsoup4==4.6.3'] diff --git a/custom_components/enigma/manifest.json b/custom_components/enigma/manifest.json index 566669a..bb0ad60 100644 --- a/custom_components/enigma/manifest.json +++ b/custom_components/enigma/manifest.json @@ -1,7 +1,7 @@ { "domain": "enigma", "name": "Enigma2 addon", - "version" : "1.5", + "version" : "1.6", "documentation": "https://github.com/cinzas/homeassistant-enigma-player", "issue_tracker": "https://github.com/cinzas/homeassistant-enigma-player/issues", "dependencies": [], diff --git a/custom_components/enigma/media_player.py b/custom_components/enigma/media_player.py index 3c6699e..dfd0cec 100644 --- a/custom_components/enigma/media_player.py +++ b/custom_components/enigma/media_player.py @@ -48,7 +48,7 @@ from homeassistant.util import Throttle # VERSION -VERSION = '1.3' +VERSION = '1.6' # Dependencies DEPENDENCIES = ['enigma'] @@ -141,7 +141,7 @@ async def load_sources(self): (self._bouquet)) # Channels name - soup = BeautifulSoup(epgbouquet_xml, 'html.parser') + soup = BeautifulSoup(epgbouquet_xml, 'lxml') src_names = soup.find_all('e2eventservicename') self._source_names = [src_name.string for src_name in src_names] # Channels reference @@ -158,7 +158,7 @@ async def load_sources(self): epgbouquet_xml = await self.request_call('/web/epgnow?bRef=' + reference) # Channels name - soup = BeautifulSoup(epgbouquet_xml, 'html.parser') + soup = BeautifulSoup(epgbouquet_xml, 'lxml') src_names = soup.find_all('e2eventservicename') self._source_names = [src_name.string for src_name in src_names] @@ -173,7 +173,7 @@ async def get_bouquet_reference(self): from bs4 import BeautifulSoup # Get first bouquet reference bouquets_xml = await self.request_call('/web/getallservices') - soup = BeautifulSoup(bouquets_xml, 'html.parser') + soup = BeautifulSoup(bouquets_xml, 'lxml') return soup.find('e2servicereference').renderContents().decode('UTF8') # Asnc API requests @@ -201,7 +201,7 @@ async def async_update(self): _LOGGER.debug("Enigma: [update] - request for host %s (%s)", self._host, self._name) powerstate_xml = await self.request_call('/web/powerstate') - powerstate_soup = BeautifulSoup(powerstate_xml, 'html.parser') + powerstate_soup = BeautifulSoup(powerstate_xml, 'lxml') pwstate = powerstate_soup.e2instandby.renderContents().decode('UTF8') self._pwstate = '' @@ -216,7 +216,7 @@ async def async_update(self): # If name was not defined, get the name from the box if self._name == 'Enigma2 Satelite': about_xml = await self.request_call('/web/about') - soup = BeautifulSoup(about_xml, 'html.parser') + soup = BeautifulSoup(about_xml, 'lxml') name = soup.e2model.renderContents().decode('UTF8') _LOGGER.debug("Enigma: [update] - Name for host %s = %s", self._host, name) @@ -226,7 +226,7 @@ async def async_update(self): # If powered on if self._pwstate == 'false': subservices_xml = await self.request_call('/web/subservices') - soup = BeautifulSoup(subservices_xml, 'html.parser') + soup = BeautifulSoup(subservices_xml, 'lxml') servicename = soup.e2servicename.renderContents().decode('UTF8') reference = soup.e2servicereference.renderContents().decode('UTF8') eventid = 'N/A' @@ -236,7 +236,7 @@ async def async_update(self): if reference != '' and reference != 'N/A' and \ not reference.startswith('1:0:0:0:0:0:0:0:0:0:'): xml = await self.request_call('/web/epgservicenow?sRef=' + reference) - soup = BeautifulSoup(xml, 'html.parser') + soup = BeautifulSoup(xml, 'lxml') eventtitle = soup.e2eventtitle.renderContents().decode('UTF8') eventid = soup.e2eventid.renderContents().decode('UTF8') if self._password != DEFAULT_PASSWORD: @@ -279,7 +279,7 @@ async def async_update(self): # Check volume and if is muted and update self variables volume_xml = await self.request_call('/web/vol') - soup = BeautifulSoup(volume_xml, 'html.parser') + soup = BeautifulSoup(volume_xml, 'lxml') volcurrent = soup.e2current.renderContents().decode('UTF8') volmuted = soup.e2ismuted.renderContents().decode('UTF8') @@ -370,58 +370,49 @@ def source_list(self): return self._source_names # SET - Change channel - From dropbox menu - @asyncio.coroutine async def async_select_source(self, source): """Select input source.""" _LOGGER.debug("Enigma: [async_select_source] - Change source channel") await self.request_call('/web/zap?sRef=' + self._sources[source]) # SET - Volume up - @asyncio.coroutine async def async_volume_up(self): """Set volume level up.""" await self.request_call('/web/vol?set=up') # SET - Volume down - @asyncio.coroutine async def async_volume_down(self): """Set volume level down.""" await self.request_call('/web/vol?set=down') # SET - Volume level - @asyncio.coroutine async def async_set_volume_level(self, volume): """Set volume level, range 0..1.""" volset = str(round(volume * MAX_VOLUME)) await self.request_call('/web/vol?set=set' + volset) # SET - Volume mute - @asyncio.coroutine async def async_mute_volume(self, mute): """Mute or unmute media player.""" await self.request_call('/web/vol?set=mute') # SET - Media Play/pause - @asyncio.coroutine async def async_media_play_pause(self): """Simulate play pause media player.""" _LOGGER.debug("Enigma: [play_pause_toogle] - Does nothing") # SET - Media Play - @asyncio.coroutine async def async_media_play(self): """Send play command.""" _LOGGER.debug("Enigma: [play] - Does nothing") # SET - Media Pause - @asyncio.coroutine async def async_media_pause(self): """Send media pause command to media player.""" _LOGGER.debug("Enigma: [pause] - Does nothing") # SET - Change to channel number - @asyncio.coroutine async def async_play_media(self, media_type, media_id, **kwargs): """Support changing a channel.""" if media_type != MEDIA_TYPE_CHANNEL: @@ -451,26 +442,22 @@ async def async_play_media(self, media_type, media_id, **kwargs): await self.request_call('/web/remotecontrol?command='+str(channel_digit)) # SET - Turn on - @asyncio.coroutine async def async_turn_on(self): """Turn the media player on.""" await self.request_call('/web/powerstate?newstate=4') self.async_update() # SET - Turn of - @asyncio.coroutine async def async_turn_off(self): """Turn off media player.""" await self.request_call('/web/powerstate?newstate=5') # SET - Next channel - @asyncio.coroutine async def async_media_next_track(self): """Change to next channel.""" await self.request_call('/web/remotecontrol?command=106') # SET - Previous channel - @asyncio.coroutine async def async_media_previous_track(self): """Change to previous channel.""" await self.request_call('/web/remotecontrol?command=105') diff --git a/custom_components/enigma/notify.py b/custom_components/enigma/notify.py index 3e1956d..33b6e52 100644 --- a/custom_components/enigma/notify.py +++ b/custom_components/enigma/notify.py @@ -32,7 +32,7 @@ # VERSION -VERSION = '1.4' +VERSION = '1.6' # Default value for display (if not passed as argument in data field) # 20 seconds for timeout @@ -105,7 +105,6 @@ async def request_call(self, url): _LOGGER.exception("[Enigma Notify]: [request_call] - Error connecting to \ remote enigma") - @asyncio.coroutine async def async_send_message(self, message="", **kwargs): """Send message.""" try: