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

Commit

Permalink
Merge pull request #74 from andrewsayre/dev
Browse files Browse the repository at this point in the history
Version 0.7.8
- added support for windowShadeLevel capability
- Updated python target versions
- Updated dependencies
  • Loading branch information
andrewsayre committed Jul 12, 2023
2 parents b539c71 + ca4917e commit a1629cc
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 48 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
name: "Check style and lint"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.9
- uses: actions/cache@v2
python-version: "3.11"
- uses: actions/cache@v3
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('test-requirements.txt') }}
Expand All @@ -40,14 +40,14 @@ jobs:
needs: lint
strategy:
matrix:
python-version: [3.8, 3.9]
python-version: ["3.10", "3.11"]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v2
- uses: actions/cache@v3
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('test-requirements.txt') }}
Expand All @@ -63,12 +63,12 @@ jobs:
runs-on: ubuntu-latest
needs: lint
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.9
- uses: actions/cache@v2
python-version: "3.11"
- uses: actions/cache@v3
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('test-requirements.txt') }}
Expand All @@ -79,6 +79,6 @@ jobs:
- name: Run pytest on ${{ matrix.python-version }}
run: pytest --cov=./ --cov-report=xml
- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
fail_ci_if_error: true
10 changes: 5 additions & 5 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ jobs:
name: "Package and Publish"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.9
- uses: actions/cache@v2
python-version: "3.11"
- uses: actions/cache@v3
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('test-requirements.txt') }}
- name: Install dependencies
- name: Install dependenciesgit
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt -r test-requirements.txt --upgrade --upgrade-strategy eager
Expand Down
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.formatting.provider": "black",
"python.formatting.provider": "none",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
Expand All @@ -16,5 +16,8 @@
"when": "$(basename).py"
},
"**/__pycache__": true
},
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
}
}
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,10 @@ Devices with the `switchLevel` capability have the following function that sets
result = await device.set_level(75, 2)
assert result == True
```

Devices with the `windowShadeLevel` capability have the following function that sets the target shade level.

```pythonstub
result = await device.set_window_shade_level(50)
assert result == True
```
2 changes: 0 additions & 2 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# unnecessary-pass - readability for functions which only contain pass
disable=
format,
abstract-class-little-used,
abstract-method,
cyclic-import,
duplicate-code,
Expand All @@ -25,7 +24,6 @@ disable=
locally-disabled,
not-an-iterable,
not-context-manager,
redefined-variable-type,
too-few-public-methods,
too-many-arguments,
too-many-branches,
Expand Down
4 changes: 1 addition & 3 deletions pysmartthings/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ def app_type(self) -> str:
def app_type(self, value: str):
"""Set the app type."""
if value not in (APP_TYPE_LAMBDA, APP_TYPE_WEBHOOK):
raise ValueError(
"value must be 'LAMBDA_SMART_APP' " "or 'WEBHOOK_SMART_APP'"
)
raise ValueError("value must be 'LAMBDA_SMART_APP' or 'WEBHOOK_SMART_APP'")
self._app_type = value

@property
Expand Down
7 changes: 7 additions & 0 deletions pysmartthings/capability.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@
],
"waterSensor": ["water"],
"windowShade": ["windowShade"],
"windowShadeLevel": ["shadeLevel"],
"windowShadePreset": ["presetPosition"],
}
CAPABILITIES = list(CAPABILITIES_TO_ATTRIBUTES)
ATTRIBUTES = {
Expand Down Expand Up @@ -241,6 +243,8 @@ class Capability:
washer_operating_state = "washerOperatingState"
water_sensor = "waterSensor"
window_shade = "windowShade"
window_shade_level = "windowShadeLevel"
window_shade_preset = "windowShadePreset"


class Attribute:
Expand Down Expand Up @@ -327,6 +331,7 @@ class Attribute:
power_consumption = "powerConsumption"
power_source = "powerSource"
presence = "presence"
preset_position = "presetPosition"
progress = "progress"
rapid_cooling = "rapidCooling"
refrigeration_setpoint = "refrigerationSetpoint"
Expand All @@ -336,12 +341,14 @@ class Attribute:
rssi = "rssi"
saturation = "saturation"
schedule = "schedule"
shade_level = "shadeLevel"
smoke = "smoke"
sound = "sound"
st = "st"
supported_ac_fan_modes = "supportedAcFanModes"
supported_ac_modes = "supportedAcModes"
supported_button_values = "supportedButtonValues"
supported_fan_oscillation_modes = "supportedFanOscillationModes"
supported_input_sources = "supportedInputSources"
supported_machine_states = "supportedMachineStates"
supported_playback_commands = "supportedPlaybackCommands"
Expand Down
2 changes: 1 addition & 1 deletion pysmartthings/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Define consts for the pysmartthings package."""

__title__ = "pysmartthings"
__version__ = "0.7.7"
__version__ = "0.7.8"
37 changes: 36 additions & 1 deletion pysmartthings/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Command:
set_saturation = "setSaturation"
set_thermostat_fan_mode = "setThermostatFanMode"
set_thermostat_mode = "setThermostatMode"
set_shade_level = "setShadeLevel"
unlock = "unlock"
mute = "mute"
unmute = "unmute"
Expand Down Expand Up @@ -727,6 +728,18 @@ def media_title(self) -> bool:
"""Get the trackDescription attribute."""
return self._attributes["trackDescription"].value

@property
def shade_level(self) -> int:
"""Get the shadeLevel attribute, scaled 0-100."""
return int(self._attributes[Attribute.shade_level].value or 0)

@shade_level.setter
def shade_level(self, value: int):
"""Set the level of the attribute, scaled 0-100."""
if not 0 <= value <= 100:
raise ValueError("value must be scaled between 0-100.")
self.update_attribute_value(Attribute.shade_level, value)


class DeviceStatus(DeviceStatusBase):
"""Define the device status."""
Expand Down Expand Up @@ -848,7 +861,7 @@ async def set_color(
if color_hex:
if not COLOR_HEX_MATCHER.match(color_hex):
raise ValueError(
"color_hex was not a properly formatted " "color hex, i.e. #000000."
"color_hex was not a properly formatted color hex, i.e. #000000."
)
color_map["hex"] = color_hex
else:
Expand Down Expand Up @@ -1390,6 +1403,28 @@ async def channel_down(
component_id, Capability.tv_channel, Command.channel_down
)

async def set_window_shade_level(
self,
level: int,
set_status: bool = False,
*,
component_id: str = "main",
) -> bool:
"""Call the set shade level device command."""
if not 0 <= level <= 100:
raise ValueError("level must be scaled between 0-100.")

result = await self.command(
component_id,
Capability.window_shade_level,
Command.set_shade_level,
[level],
)
if result and set_status:
self.status.shade_level = level
self.status.switch = level > 0
return result

@property
def status(self):
"""Get the status entity of the device."""
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
aiohttp==3.8.0
aiohttp==3.8.4
2 changes: 1 addition & 1 deletion script/generate_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def main():
attribs = [a for a in ATTRIBUTES]
attribs.sort()
for a in attribs:
print("{} = '{}'".format(re.sub(r"([A-Z])", r"_\1", a).lower(), a))
print('{} = "{}"'.format(re.sub(r"([A-Z])", r"_\1", a).lower(), a))


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion script/generate_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def main():
capabilities = CAPABILITIES.copy()
capabilities.sort()
for c in capabilities:
print("{} = '{}'".format(re.sub(r"([A-Z])", r"_\1", c).lower(), c))
print('{} = "{}"'.format(re.sub(r"([A-Z])", r"_\1", c).lower(), c))


if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
author_email="andrew@sayre.net",
license="ASL 2.0",
packages=find_packages(exclude=("tests*",)),
install_requires=["aiohttp>=3.8.0,<4.0.0"],
install_requires=["aiohttp>=3.8.4,<4.0.0"],
tests_require=[],
platforms=["any"],
keywords="smartthings",
Expand All @@ -36,7 +36,7 @@
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries",
"Topic :: Home Automation",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
)
24 changes: 12 additions & 12 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
black==21.10b0
coveralls==3.3.0
flake8==4.0.1
flake8-docstrings==1.6.0
pydocstyle==6.1.1
isort==5.10.1
pylint==2.11.1
pytest==6.2.5
pytest-asyncio==0.16.0
pytest-cov==3.0.0
pytest-timeout==2.0.1
yarl==1.7.2
black==23.3.0
coveralls==3.3.1
flake8==6.0.0
flake8-docstrings==1.7.0
pydocstyle==6.3.0
isort==5.12.0
pylint==2.17.4
pytest==7.4.0
pytest-asyncio==0.21.0
pytest-cov==4.1.0
pytest-timeout==2.1.0
yarl==1.9.2
10 changes: 10 additions & 0 deletions tests/json/device_command_post_set_shade_level.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"commands": [
{
"component": "main",
"capability": "windowShadeLevel",
"command": "setShadeLevel",
"arguments": [75]
}
]
}

0 comments on commit a1629cc

Please sign in to comment.