Skip to content

Commit

Permalink
Merge pull request #26 from kingy444/master
Browse files Browse the repository at this point in the history
Bug Fix for Shade Capabilities
  • Loading branch information
kingy444 authored Sep 29, 2022
2 parents 71bf0ab + b88d1ae commit a51e965
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 34 deletions.
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ Changelog

- Invert type 3 & 4 to match api documentation from hunter douglas
- Add type 10

**v2.0.2**

- Bug Fix to handle shades with unexpected json responses
2 changes: 1 addition & 1 deletion aiopvapi/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Aio PowerView api version."""

__version__ = "2.0.1"
__version__ = "2.0.2"
111 changes: 78 additions & 33 deletions aiopvapi/resources/shade.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
@dataclass
class ShadeCapabilities:
"""Represents the capabilities available for shade."""

primary: bool = False
secondary: bool = False
tilt90: bool = False
Expand All @@ -50,6 +51,7 @@ class ShadeCapabilities:
@dataclass
class ShadeLimits:
"""Represents the limits of a shade."""

primary_min: int = MIN_POSITION
primary_max: int = MAX_POSITION
secondary_min: int = MIN_POSITION
Expand All @@ -65,6 +67,7 @@ class ShadeLimits:
def factory(raw_data, request):
"""Class factory to create different types of shades
depending on shade type."""

if ATTR_SHADE in raw_data:
raw_data = raw_data.get(ATTR_SHADE)

Expand Down Expand Up @@ -104,6 +107,8 @@ def find_capability(shade):
if _shade:
_LOGGER.debug("Match type : %s - %s", _shade, raw_data)
return _shade

for cls in classes:
# fallback to a capability check - this should future proof new shades
# type 0 that contain tilt would not be caught here
_shade = find_capability(cls)
Expand Down Expand Up @@ -274,8 +279,10 @@ class ShadeBottomUp(BaseShade):

capability = capability(
0,
ShadeCapabilities(primary=True),
"Bottom Up"
ShadeCapabilities(
primary=True,
),
"Bottom Up",
)

open_position = {ATTR_POSITION1: MAX_POSITION, ATTR_POSKIND1: 1}
Expand All @@ -300,8 +307,12 @@ class ShadeBottomUpTiltOnClosed(BaseShadeTilt):

capability = capability(
0,
ShadeCapabilities(primary=True, tiltOnClosed=True, tilt180=True),
"Bottom Up Tilt 180°"
ShadeCapabilities(
primary=True,
tiltOnClosed=True,
tilt180=True,
),
"Bottom Up Tilt 180°",
)

open_position = {ATTR_POSITION1: MAX_POSITION, ATTR_POSKIND1: 1}
Expand Down Expand Up @@ -330,8 +341,12 @@ class ShadeBottomUpTiltOnClosed90(BaseShadeTilt):

capability = capability(
1,
ShadeCapabilities(primary=True, tiltOnClosed=True, tilt90=True),
"Bottom Up Tilt 90°"
ShadeCapabilities(
primary=True,
tiltOnClosed=True,
tilt90=True,
),
"Bottom Up Tilt 90°",
)

shade_limits = ShadeLimits(tilt_max=MID_POSITION)
Expand Down Expand Up @@ -361,8 +376,12 @@ class ShadeBottomUpTiltAnywhere(BaseShadeTilt):

capability = capability(
2,
ShadeCapabilities(primary=True, tiltAnywhere=True, tilt180=True),
"Bottom Up Tilt 180°"
ShadeCapabilities(
primary=True,
tiltAnywhere=True,
tilt180=True,
),
"Bottom Up Tilt 180°",
)

open_position = {
Expand Down Expand Up @@ -403,8 +422,11 @@ class ShadeVertical(ShadeBottomUp):

capability = capability(
3,
ShadeCapabilities(primary=True, vertical=True),
"Vertical"
ShadeCapabilities(
primary=True,
vertical=True,
),
"Vertical",
)


Expand All @@ -423,9 +445,13 @@ class ShadeVerticalTiltAnywhere(ShadeBottomUpTiltAnywhere):

capability = capability(
4,
ShadeCapabilities(primary=True, tiltAnywhere=True,
tilt180=True, vertical=True),
"Vertical Tilt Anywhere"
ShadeCapabilities(
primary=True,
tiltAnywhere=True,
tilt180=True,
vertical=True,
),
"Vertical Tilt Anywhere",
)


Expand All @@ -441,8 +467,11 @@ class ShadeTiltOnly(BaseShadeTilt):

capability = capability(
5,
ShadeCapabilities(tiltAnywhere=True, tilt180=True),
"Tilt Only 180°"
ShadeCapabilities(
tiltAnywhere=True,
tilt180=True,
),
"Tilt Only 180°",
)

open_position = {}
Expand Down Expand Up @@ -472,8 +501,11 @@ class ShadeTopDown(BaseShade):

capability = capability(
6,
ShadeCapabilities(primary=True, primaryInverted=True),
"Top Down"
ShadeCapabilities(
primary=True,
primaryInverted=True,
),
"Top Down",
)

open_position = {ATTR_POSITION1: MIN_POSITION, ATTR_POSKIND1: 1}
Expand All @@ -494,13 +526,16 @@ class ShadeTopDownBottomUp(BaseShade):
shade_type(8, "Duette, Top Down Bottom Up"),
shade_type(9, "Duette DuoLite, Top Down Bottom Up"),
shade_type(33, "Duette Architella, Top Down Bottom Up"),
shade_type(47, "Pleated, Top Down Bottom Up"),
shade_type(47, "Pleated, Top Down Bottom Up"),
)

capability = capability(
7,
ShadeCapabilities(primary=True, secondary=True),
"Top Down Bottom Up"
ShadeCapabilities(
primary=True,
secondary=True,
),
"Top Down Bottom Up",
)

open_position = {
Expand Down Expand Up @@ -535,9 +570,12 @@ class ShadeDualOverlapped(BaseShade):

capability = capability(
8,
ShadeCapabilities(primary=True, secondary=True,
secondaryOverlapped=True),
"Dual Shade Overlapped"
ShadeCapabilities(
primary=True,
secondary=True,
secondaryOverlapped=True,
),
"Dual Shade Overlapped",
)

open_position = {ATTR_POSITION1: MAX_POSITION, ATTR_POSKIND1: 1}
Expand All @@ -562,10 +600,14 @@ class ShadeDualOverlappedTilt90(BaseShadeTilt):

capability = capability(
9,
ShadeCapabilities(primary=True, secondary=True,
secondaryOverlapped=True, tilt90=True,
tiltOnClosed=True),
"Dual Shade Overlapped Tilt 90°"
ShadeCapabilities(
primary=True,
secondary=True,
secondaryOverlapped=True,
tilt90=True,
tiltOnClosed=True,
),
"Dual Shade Overlapped Tilt 90°",
)

shade_limits = ShadeLimits(tilt_max=MID_POSITION)
Expand All @@ -583,7 +625,6 @@ class ShadeDualOverlappedTilt90(BaseShadeTilt):
)



class ShadeDualOverlappedTilt180(ShadeDualOverlappedTilt90):
"""Type 10 - Dual Shade Overlapped with tiltOnClosed
Expand All @@ -596,10 +637,14 @@ class ShadeDualOverlappedTilt180(ShadeDualOverlappedTilt90):

capability = capability(
10,
ShadeCapabilities(primary=True, secondary=True,
secondaryOverlapped=True, tilt180=True,
tiltOnClosed=True),
"Dual Shade Overlapped Tilt 180°"
ShadeCapabilities(
primary=True,
secondary=True,
secondaryOverlapped=True,
tilt180=True,
tiltOnClosed=True,
),
"Dual Shade Overlapped Tilt 180°",
)

shade_limits = ShadeLimits(tilt_max=MAX_POSITION)
shade_limits = ShadeLimits(tilt_max=MAX_POSITION)
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Have a look at the examples folder for some guidance how to use it.
- Invert type 3 & 4 to match api documentation from hunter douglas
- Add type 10

### v2.0.2

- Bug Fix to handle shades with unexpected json responses

## Links

---
Expand Down

0 comments on commit a51e965

Please sign in to comment.