Skip to content

Commit

Permalink
@asyncio.coroutine decorator is removed in Python 3.11. Async keyowrd…
Browse files Browse the repository at this point in the history
… already being used. Changed beautifulsoup parser from html to lxml, avoiding the warning on homeassistant
  • Loading branch information
cinzas committed Jun 8, 2023
1 parent 7ea71a0 commit d393850
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 26 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

2 changes: 1 addition & 1 deletion custom_components/enigma/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from homeassistant.helpers.entity import Entity

# VERSION
VERSION = '1.4'
VERSION = '1.6'

# REQUIREMENTS
REQUIREMENTS = ['beautifulsoup4==4.6.3']
Expand Down
2 changes: 1 addition & 1 deletion custom_components/enigma/manifest.json
Original file line number Diff line number Diff line change
@@ -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": [],
Expand Down
31 changes: 9 additions & 22 deletions custom_components/enigma/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
from homeassistant.util import Throttle

# VERSION
VERSION = '1.3'
VERSION = '1.6'

# Dependencies
DEPENDENCIES = ['enigma']
Expand Down Expand Up @@ -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
Expand All @@ -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]

Expand All @@ -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
Expand Down Expand Up @@ -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 = ''

Expand All @@ -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)
Expand All @@ -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'
Expand All @@ -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:
Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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')
3 changes: 1 addition & 2 deletions custom_components/enigma/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit d393850

Please sign in to comment.