Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #110 from akloeckner/fix/wiim
Browse files Browse the repository at this point in the history
feat: add initial support for Wiim Mini device
  • Loading branch information
nagyrobi authored Jun 29, 2023
2 parents c2cdac8 + aa4bcd4 commit 945a71e
Showing 1 changed file with 36 additions and 26 deletions.
62 changes: 36 additions & 26 deletions custom_components/linkplay/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,43 +236,48 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=

state = STATE_IDLE

initurl = "http://{0}/httpapi.asp?command=getStatus".format(host)
websession = async_get_clientsession(hass)
response = None

try:
websession = async_get_clientsession(hass)
response = await websession.get(initurl)
protocol = "http"
initurl = "{}://{}/httpapi.asp?command=getStatus"
response = await websession.get(initurl.format(protocol,host))

if response.status == HTTPStatus.OK:
data = await response.json(content_type=None)
_LOGGER.debug("HOST: %s DATA response: %s", host, data)

try:
uuid = data['uuid']
except KeyError:
pass
except (asyncio.TimeoutError, aiohttp.ClientError) as error:

if name == None:
try:
name = data['DeviceName']
except KeyError:
pass
try:
protocol = "https"
initurl = "{}://{}/httpapi.asp?command=getStatusEx"
response = await websession.get(initurl.format(protocol,host), ssl=False)

else:
except (asyncio.TimeoutError, aiohttp.ClientError) as error:
_LOGGER.warning(
"Get Status UUID failed, response code: %s Full message: %s",
response.status,
response,
"Failed communicating with LinkPlayDevice (start) '%s': uuid: %s %s", host, uuid, type(error)
)
state = STATE_UNAVAILABLE

except (asyncio.TimeoutError, aiohttp.ClientError) as error:
if response and response.status == HTTPStatus.OK:
data = await response.json(content_type=None)
_LOGGER.debug("HOST: %s DATA response: %s", host, data)

if 'uuid' in data:
uuid = data['uuid']

if 'DeviceName' in data and name == None:
name = data['DeviceName']

else:
_LOGGER.warning(
"Failed communicating with LinkPlayDevice (start) '%s': uuid: %s %s", host, uuid, type(error)
"Get Status UUID failed, response code: %s Full message: %s",
response.status,
response,
)
state = STATE_UNAVAILABLE

linkplay = LinkPlayDevice(name,
host,
protocol,
sources,
common_sources,
icecast_metadata,
Expand All @@ -291,7 +296,8 @@ class LinkPlayDevice(MediaPlayerEntity):

def __init__(self,
name,
host,
host,
protocol,
sources,
common_sources,
icecast_metadata,
Expand All @@ -314,6 +320,7 @@ def __init__(self,
self._preset_key = 4
self._name = name
self._host = host
self._protocol = protocol
self._icon = ICON_DEFAULT
self._state = state
self._volume = 0
Expand Down Expand Up @@ -397,7 +404,7 @@ async def async_added_to_hass(self):

async def call_linkplay_httpapi(self, cmd, jsn):
"""Get the latest data from HTTPAPI service."""
url = "http://{0}/httpapi.asp?command={1}".format(self._host, cmd)
url = "{}://{}/httpapi.asp?command={}".format(self._protocol, self._host, cmd)

if self._first_update:
timeout = 10
Expand All @@ -407,7 +414,7 @@ async def call_linkplay_httpapi(self, cmd, jsn):
try:
websession = async_get_clientsession(self.hass)
async with async_timeout.timeout(timeout):
response = await websession.get(url)
response = await websession.get(url, ssl=False)

except (asyncio.TimeoutError, aiohttp.ClientError) as error:
_LOGGER.warning(
Expand Down Expand Up @@ -551,7 +558,10 @@ async def async_update(self):
self._unav_throttle = False
if self._first_update or (self._state == STATE_UNAVAILABLE or self._multiroom_wifidirect):
#_LOGGER.debug("03 Update first time getStatus %s, %s", self.entity_id, self._name)
device_status = await self.call_linkplay_httpapi("getStatus", True)
if self._protocol == "https":
device_status = await self.call_linkplay_httpapi("getStatusEx", True)
else:
device_status = await self.call_linkplay_httpapi("getStatus", True)
if device_status is not None:
if isinstance(device_status, dict):
if self._state == STATE_UNAVAILABLE:
Expand Down

0 comments on commit 945a71e

Please sign in to comment.