diff --git a/homepilot/actuator.py b/homepilot/actuator.py index 64987dc..553112b 100644 --- a/homepilot/actuator.py +++ b/homepilot/actuator.py @@ -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: diff --git a/homepilot/api.py b/homepilot/api.py index 50081ee..22395d1 100644 --- a/homepilot/api.py +++ b/homepilot/api.py @@ -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, ) @@ -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( @@ -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() @@ -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() diff --git a/homepilot/const.py b/homepilot/const.py index f1f0047..9a8de17 100644 --- a/homepilot/const.py +++ b/homepilot/const.py @@ -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 = { diff --git a/homepilot/cover.py b/homepilot/cover.py index ad1bd05..5862097 100644 --- a/homepilot/cover.py +++ b/homepilot/cover.py @@ -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) diff --git a/homepilot/light.py b/homepilot/light.py index 40a504c..1c2cd9e 100644 --- a/homepilot/light.py +++ b/homepilot/light.py @@ -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) @@ -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() diff --git a/setup.py b/setup.py index 91fd087..fa2f9a1 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="pyrademacher", - version="0.13.7", + version="0.14.0", author="Pedro Ribeiro", author_email="pedroeusebio@gmail.com", description="Control devices connected to your Rademacher Homepilot " diff --git a/tests/test_api.py b/tests/test_api.py index c8a4b41..4cfa85b 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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: @@ -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): diff --git a/tests/test_cover.py b/tests/test_cover.py index af340bb..85b1809 100644 --- a/tests/test_cover.py +++ b/tests/test_cover.py @@ -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 @@ -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):