py-ccm15 0.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
py-ccm15-0.0.3/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Oscar Calvo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,15 @@
1
+ Metadata-Version: 2.1
2
+ Name: py-ccm15
3
+ Version: 0.0.3
4
+ Summary: A package to control Midea CCM15 data converter modules
5
+ Home-page: https://github.com/ocalvo/py-ccm15
6
+ Author: Oscar Calvo
7
+ Author-email: oscar@calvonet.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+
14
+ # py-ccm15
15
+ Python Library to access a Midea CCM15 data converter
@@ -0,0 +1,2 @@
1
+ # py-ccm15
2
+ Python Library to access a Midea CCM15 data converter
@@ -0,0 +1,41 @@
1
+ import httpx
2
+ import xmltodict
3
+ from .CCM15DeviceState import CCM15DeviceState
4
+ from .CCM15SlaveDevice import CCM15SlaveDevice
5
+
6
+ BASE_URL = "http://{0}:{1}/{2}"
7
+ CONF_URL_STATUS = "status.xml"
8
+ DEFAULT_TIMEOUT = 10
9
+
10
+ class CCM15Device:
11
+ def __init__(self, host: str, port: int, timeout = DEFAULT_TIMEOUT):
12
+ self.host = host
13
+ self.port = port
14
+ self.timeout = timeout
15
+
16
+ async def _fetch_xml_data(self) -> str:
17
+ url = BASE_URL.format(self.host, self.port, CONF_URL_STATUS)
18
+ async with httpx.AsyncClient() as client:
19
+ response = await client.get(url, self.timeout)
20
+ return response.text
21
+
22
+ async def _fetch_data(self) -> CCM15DeviceState:
23
+ """Get the current status of all AC devices."""
24
+ str_data = await self._fetch_xml_data()
25
+ doc = xmltodict.parse(str_data)
26
+ data = doc["response"]
27
+ ac_data = CCM15DeviceState(devices={})
28
+ ac_index = 0
29
+ for ac_name, ac_binary in data.items():
30
+ if ac_binary == "-":
31
+ break
32
+ bytesarr = bytes.fromhex(ac_binary.strip(","))
33
+ ac_slave = CCM15SlaveDevice(bytesarr)
34
+ ac_data.devices[ac_index] = ac_slave
35
+ ac_index += 1
36
+ return ac_data
37
+
38
+ async def get_status_async(self) -> CCM15DeviceState:
39
+ return await self._fetch_data()
40
+
41
+
@@ -0,0 +1,9 @@
1
+ """Data model to represent state of a CCM15 device."""
2
+ from dataclasses import dataclass
3
+ from . import CCM15SlaveDevice
4
+
5
+ @dataclass
6
+ class CCM15DeviceState:
7
+ """Data retrieved from a CCM15 device."""
8
+
9
+ devices: dict[int, CCM15SlaveDevice]
@@ -0,0 +1,54 @@
1
+ """Data model to represent state of a CCM15 device."""
2
+ from dataclasses import dataclass
3
+ from enum import Enum
4
+
5
+ @dataclass
6
+ class TemperatureUnit(Enum):
7
+ CELSIUS = 1
8
+ FAHRENHEIT = 2
9
+
10
+ @dataclass
11
+ class CCM15SlaveDevice:
12
+ """Data retrieved from a CCM15 slave device."""
13
+
14
+ def __init__(self, bytesarr: bytes) -> None:
15
+ """Initialize the slave device."""
16
+ self.unit = TemperatureUnit.CELSIUS
17
+ buf = bytesarr[0]
18
+ if (buf >> 0) & 1:
19
+ self.unit = TemperatureUnit.FAHRENHEIT
20
+ self.locked_cool_temperature: int = (buf >> 3) & 0x1F
21
+
22
+ buf = bytesarr[1]
23
+ self.locked_heat_temperature: int = (buf >> 0) & 0x1F
24
+ self.locked_wind: int = (buf >> 5) & 7
25
+
26
+ buf = bytesarr[2]
27
+ self.locked_ac_mode: int = (buf >> 0) & 3
28
+ self.error_code: int = (buf >> 2) & 0x3F
29
+
30
+ buf = bytesarr[3]
31
+ self.ac_mode: int = (buf >> 2) & 7
32
+ self.fan_mode: int = (buf >> 5) & 7
33
+
34
+ buf = (buf >> 1) & 1
35
+ self.is_ac_mode_locked: bool = buf != 0
36
+
37
+ buf = bytesarr[4]
38
+ self.temperature_setpoint: int = (buf >> 3) & 0x1F
39
+ if self.unit == TemperatureUnit.FAHRENHEIT:
40
+ self.temperature_setpoint += 62
41
+ self.locked_cool_temperature += 62
42
+ self.locked_heat_temperature += 62
43
+ self.is_swing_on: bool = (buf >> 1) & 1 != 0
44
+
45
+ buf = bytesarr[5]
46
+ if ((buf >> 3) & 1) == 0:
47
+ self.locked_cool_temperature = 0
48
+ if ((buf >> 4) & 1) == 0:
49
+ self.locked_heat_temperature = 0
50
+ self.fan_locked: bool = buf >> 5 & 1 != 0
51
+ self.is_remote_locked: bool = ((buf >> 6) & 1) != 0
52
+
53
+ buf = bytesarr[6]
54
+ self.temperature: int = buf if buf < 128 else buf - 256
@@ -0,0 +1,8 @@
1
+ """ Init file """
2
+
3
+ from .CCM15Device import CCM15Device
4
+ from .CCM15DeviceState import CCM15DeviceState
5
+ from .CCM15SlaveDevice import CCM15SlaveDevice, TemperatureUnit
6
+
7
+ __all__ = ['CCM15Device', 'CCM15DeviceState', 'CCM15SlaveDevice', 'TemperatureUnit']
8
+
@@ -0,0 +1,15 @@
1
+ Metadata-Version: 2.1
2
+ Name: py-ccm15
3
+ Version: 0.0.3
4
+ Summary: A package to control Midea CCM15 data converter modules
5
+ Home-page: https://github.com/ocalvo/py-ccm15
6
+ Author: Oscar Calvo
7
+ Author-email: oscar@calvonet.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+
14
+ # py-ccm15
15
+ Python Library to access a Midea CCM15 data converter
@@ -0,0 +1,14 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ ccm15/CCM15Device.py
5
+ ccm15/CCM15DeviceState.py
6
+ ccm15/CCM15SlaveDevice.py
7
+ ccm15/__init__.py
8
+ py_ccm15.egg-info/PKG-INFO
9
+ py_ccm15.egg-info/SOURCES.txt
10
+ py_ccm15.egg-info/dependency_links.txt
11
+ py_ccm15.egg-info/requires.txt
12
+ py_ccm15.egg-info/top_level.txt
13
+ tests/test_ccm15.py
14
+ tests/test_slave.py
@@ -0,0 +1,2 @@
1
+ httpx>=0.24.1
2
+ xmltodict>=0.13.0
@@ -0,0 +1 @@
1
+ ccm15
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,25 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ with open("README.md", "r") as f:
4
+ long_description = f.read()
5
+
6
+ setup(
7
+ name="py-ccm15",
8
+ version="0.0.3",
9
+ author="Oscar Calvo",
10
+ author_email="oscar@calvonet.com",
11
+ description="A package to control Midea CCM15 data converter modules",
12
+ long_description=long_description,
13
+ long_description_content_type="text/markdown",
14
+ url="https://github.com/ocalvo/py-ccm15",
15
+ packages=find_packages(),
16
+ classifiers=[
17
+ "Programming Language :: Python :: 3",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Operating System :: OS Independent",
20
+ ],
21
+ install_requires=[
22
+ 'httpx>=0.24.1',
23
+ 'xmltodict>=0.13.0'
24
+ ]
25
+ )
@@ -0,0 +1,29 @@
1
+ import unittest
2
+ from unittest.mock import patch, MagicMock
3
+ from ccm15 import CCM15Device, CCM15DeviceState, CCM15SlaveDevice
4
+
5
+ class TestCCM15(unittest.IsolatedAsyncioTestCase):
6
+ def setUp(self):
7
+ self.ccm = CCM15Device("localhost", 8000)
8
+
9
+ @patch("httpx.AsyncClient.get")
10
+ async def test_get_status_async(self, mock_get) -> None:
11
+ # Set up mock response
12
+ mock_response = MagicMock()
13
+ mock_response.text = """
14
+ <response>
15
+ <ac1>00000001020304</ac1>
16
+ <ac2>00000005060708</ac2>
17
+ </response>
18
+ """
19
+ mock_get.return_value = mock_response
20
+
21
+ # Call method and check result
22
+ state = await self.ccm.get_status_async()
23
+ self.assertIsInstance(state, CCM15DeviceState)
24
+ self.assertEqual(len(state.devices), 2)
25
+ self.assertIsInstance(state.devices[0], CCM15SlaveDevice)
26
+ self.assertIsInstance(state.devices[1], CCM15SlaveDevice)
27
+
28
+ if __name__ == "__main__":
29
+ unittest.main()
@@ -0,0 +1,36 @@
1
+ import unittest
2
+ from ccm15 import CCM15SlaveDevice, TemperatureUnit
3
+
4
+ class TestCCM15SlaveDevice(unittest.TestCase):
5
+ def test_swing_mode_on(self) -> None:
6
+ """Test that the swing mode is on."""
7
+ data = bytes.fromhex("00000041d2001a")
8
+ device = CCM15SlaveDevice(data)
9
+ self.assertTrue(device.is_swing_on)
10
+
11
+ def test_swing_mode_off(self) -> None:
12
+ """Test that the swing mode is off."""
13
+ data = bytes.fromhex("00000041d0001a")
14
+ device = CCM15SlaveDevice(data)
15
+ self.assertFalse(device.is_swing_on)
16
+
17
+ def test_temp_fan_mode(self) -> None:
18
+ """Test that the swing mode is on."""
19
+ data = bytes.fromhex("00000041d2001a")
20
+ device = CCM15SlaveDevice(data)
21
+ self.assertEqual(26, device.temperature)
22
+ self.assertEqual(2, device.fan_mode)
23
+ self.assertEqual(0, device.ac_mode)
24
+
25
+ def test_fahrenheit(self) -> None:
26
+ """Test that farenheith bit."""
27
+
28
+ data = bytearray.fromhex("81000041d2001a")
29
+ device = CCM15SlaveDevice(data)
30
+ self.assertEqual(TemperatureUnit.FAHRENHEIT, device.unit)
31
+ self.assertEqual(88, device.temperature_setpoint)
32
+ self.assertEqual(0, device.locked_cool_temperature)
33
+ self.assertEqual(0, device.locked_heat_temperature)
34
+
35
+ if __name__ == '__main__':
36
+ unittest.main()