Skip to content

Commit

Permalink
Merge pull request #62 from peribeir/peribeir/issue59_1
Browse files Browse the repository at this point in the history
Add support for Zigbee Lights
  • Loading branch information
peribeir authored Sep 25, 2024
2 parents 3b29029 + 1c70a4c commit a204a65
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 29 deletions.
2 changes: 1 addition & 1 deletion homepilot/actuator.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async def async_turn_off(self) -> None:
await self.api.async_turn_off(self.did)

async def async_set_brightness(self, new_brightness) -> None:
await self.api.async_set_cover_position(self.did, new_brightness)
await self.api.async_set_position(self.did, new_brightness)

async def async_toggle(self) -> None:
if self.is_on:
Expand Down
20 changes: 5 additions & 15 deletions homepilot/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
APICAP_STOP_SLAT_CMD,
APICAP_VENTIL_POS_CFG,
APICAP_VENTIL_POS_MODE_CFG,
APICAP_RGB_CFG,
APICAP_COLOR_TEMP_CFG,
APICAP_COLOR_MODE_CFG,
APICAP_SET_RGB_CMD,
APICAP_SET_COLOR_TEMP_CMD,
)


Expand Down Expand Up @@ -282,7 +281,7 @@ async def async_stop_cover(self, did):
) as response:
return await response.json()

async def async_set_cover_position(self, did, position):
async def async_set_position(self, did, position):
await self.authenticate()
async with aiohttp.ClientSession(cookie_jar=self.cookie_jar) as session:
async with session.put(
Expand Down Expand Up @@ -393,7 +392,7 @@ async def async_set_rgb(self, did, rgb_value):
async with aiohttp.ClientSession(cookie_jar=self.cookie_jar) as session:
async with session.put(
f"http://{self._host}{self._base_path}/devices/{did}",
json={"name": APICAP_RGB_CFG, "value": rgb_value},
json={"name": APICAP_SET_RGB_CMD, "value": rgb_value},
) as response:
return await response.json()

Expand All @@ -402,16 +401,7 @@ async def async_set_color_temp(self, did, color_temp_value):
async with aiohttp.ClientSession(cookie_jar=self.cookie_jar) as session:
async with session.put(
f"http://{self._host}{self._base_path}/devices/{did}",
json={"name": APICAP_COLOR_TEMP_CFG, "value": color_temp_value},
) as response:
return await response.json()

async def async_set_color_temp(self, did, color_mode_value):
await self.authenticate()
async with aiohttp.ClientSession(cookie_jar=self.cookie_jar) as session:
async with session.put(
f"http://{self._host}{self._base_path}/devices/{did}",
json={"name": APICAP_COLOR_MODE_CFG, "value": color_mode_value},
json={"name": APICAP_SET_COLOR_TEMP_CMD, "value": color_temp_value},
) as response:
return await response.json()

Expand Down
2 changes: 2 additions & 0 deletions homepilot/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@
APICAP_TEMPERATURE_THRESH_4_CFG = "TEMPERATURE_THRESH_4_CFG"
# Light
APICAP_RGB_CFG = "RGB_CFG"
APICAP_SET_RGB_CMD = "SET_RGB_CMD"
APICAP_COLOR_TEMP_CFG = "COLOR_TEMP_CFG"
APICAP_SET_COLOR_TEMP_CMD = "SET_COLOR_TEMP_CMD"
APICAP_COLOR_MODE_CFG = "COLOR_MODE_CFG"

SUPPORTED_DEVICES = {
Expand Down
4 changes: 2 additions & 2 deletions homepilot/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ async def async_close_cover(self) -> None:

async def async_set_cover_position(self, new_position) -> None:
if self.can_set_position:
await self.api.async_set_cover_position(self.did,
100 - new_position)
await self.api.async_set_position(self.did,
100 - new_position)

async def async_stop_cover(self) -> None:
await self.api.async_stop_cover(self.did)
Expand Down
5 changes: 1 addition & 4 deletions homepilot/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ async def async_turn_off(self) -> None:
await self.api.async_turn_off(self.did)

async def async_set_brightness(self, new_brightness) -> None:
await self.api.async_set_cover_position(self.did, new_brightness)
await self.api.async_set_position(self.did, new_brightness)

async def async_set_rgb(self, r, g, b) -> None:
new_rgb: str = "0x%0.6X" % (r * (2,16) + g * pow(2,8) + b)
Expand All @@ -182,9 +182,6 @@ async def async_set_rgb(self, r, g, b) -> None:
async def async_set_color_temp(self, new_color_temp) -> None:
await self.api.async_set_color_temp(self.did, new_color_temp)

async def async_set_color_mode(self, new_color_mode) -> None:
await self.api.async_set_color_mode(self.did, new_color_mode)

async def async_toggle(self) -> None:
if self.is_on:
await self.async_turn_off()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pyrademacher",
version="0.13.7",
version="0.14.0",
author="Pedro Ribeiro",
author_email="[email protected]",
description="Control devices connected to your Rademacher Homepilot "
Expand Down
4 changes: 2 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def callback_goto_pos(self, url, **kwargs):
)

@pytest.mark.asyncio
async def test_async_set_cover_position(self):
async def test_async_set_position(self):
did = "1234"
position = 40
with aioresponses() as mocked:
Expand All @@ -299,7 +299,7 @@ async def test_async_set_cover_position(self):
status=200,
callback=self.callback_goto_pos
)
assert (await instance.async_set_cover_position(did, position))[
assert (await instance.async_set_position(did, position))[
"error_code"] == 0

def callback_turn_on(self, url, **kwargs):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def mocked_api(self, event_loop):
func_stop_cover = asyncio.Future(loop=event_loop)
func_stop_cover.set_result(None)
api.async_stop_cover.return_value = func_stop_cover
func_set_cover_position = asyncio.Future(loop=event_loop)
func_set_cover_position.set_result(None)
api.async_set_cover_position.return_value = func_set_cover_position
func_set_position = asyncio.Future(loop=event_loop)
func_set_position.set_result(None)
api.async_set_position.return_value = func_set_position
func_ping = asyncio.Future(loop=event_loop)
func_ping.set_result(None)
api.async_ping.return_value = func_ping
Expand Down Expand Up @@ -99,7 +99,7 @@ async def test_async_stop_cover(self, mocked_api):
async def test_async_set_cover_position(self, mocked_api):
cover = await HomePilotCover.async_build_from_api(mocked_api, 1)
await cover.async_set_cover_position(40)
mocked_api.async_set_cover_position.assert_called_with('1', 60)
mocked_api.async_set_position.assert_called_with('1', 60)

@pytest.mark.asyncio
async def test_async_ping(self, mocked_api):
Expand Down

0 comments on commit a204a65

Please sign in to comment.