Skip to content

Commit

Permalink
change host type specific data when enabling or disabling
Browse files Browse the repository at this point in the history
  • Loading branch information
InTheDaylight14 committed Nov 13, 2024
1 parent ed098fe commit db2033a
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions custom_components/npm_switches/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,14 @@ async def enable_host(self, host_id: str, host_type: str) -> None:
response = await self.api_wrapper("post", url, headers=self._headers)

if response is True:
self.proxy_hosts_data[host_id]["enabled"] = 1
if host_type is "proxy-hosts":
self.proxy_hosts_data[host_id]["enabled"] = 1
if host_type is "redirection-hosts":
self.redir_hosts_data[host_id]["enabled"] = 1
if host_type is "streams":
self.stream_hosts_data[host_id]["enabled"] = 1
if host_type is "dead-hosts":
self.dead_hosts_data[host_id]["enabled"] = 1
elif "error" in response.keys():
_LOGGER.error(
"Error enabling host type %s host id %s. Error message: '%s'",
Expand All @@ -193,7 +200,14 @@ async def disable_host(self, host_id: str, host_type: str) -> None:

response = await self.api_wrapper("post", url, headers=self._headers)
if response is True:
self.proxy_hosts_data[host_id]["enabled"] = 0
if host_type is "proxy-hosts":
self.proxy_hosts_data[host_id]["enabled"] = 0
if host_type is "redirection-hosts":
self.redir_hosts_data[host_id]["enabled"] = 0
if host_type is "streams":
self.stream_hosts_data[host_id]["enabled"] = 0
if host_type is "dead-hosts":
self.dead_hosts_data[host_id]["enabled"] = 0
elif "error" in response.keys():
_LOGGER.error(
"Error enabling host type %s host id %s. Error message: '%s'",
Expand All @@ -215,16 +229,16 @@ def is_host_enabled(self, host_id: str, host_type: str) -> bool:
return True
else:
return False
# elif host_type == "streams":
# if self.stream_hosts_data[host_id]["enabled"] == 1:
# return True
# else:
# return False
# elif host_type == "dead-hosts":
# if self.dead_hosts_data[host_id]["enabled"] == 1:
# return True
# else:
# return False
elif host_type == "streams":
if self.stream_hosts_data[host_id]["enabled"] == 1:
return True
else:
return False
elif host_type == "dead-hosts":
if self.dead_hosts_data[host_id]["enabled"] == 1:
return True
else:
return False
else:
return None
@property
Expand Down

0 comments on commit db2033a

Please sign in to comment.