Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
72144945
Commit
72144945
authored
9 years ago
by
pavoni
Browse files
Options
Downloads
Patches
Plain Diff
Move standby from state to attribute, add optimistic switch status.
parent
35aa9aa8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
homeassistant/components/switch/wemo.py
+29
-18
29 additions, 18 deletions
homeassistant/components/switch/wemo.py
with
29 additions
and
18 deletions
homeassistant/components/switch/wemo.py
+
29
−
18
View file @
72144945
...
...
@@ -9,7 +9,8 @@ https://home-assistant.io/components/switch.wemo/
import
logging
from
homeassistant.components.switch
import
SwitchDevice
from
homeassistant.const
import
STATE_OFF
,
STATE_ON
,
STATE_STANDBY
from
homeassistant.const
import
(
STATE_OFF
,
STATE_ON
,
STATE_STANDBY
,
STATE_UNKNOWN
)
from
homeassistant.loader
import
get_component
DEPENDENCIES
=
[
'
wemo
'
]
...
...
@@ -18,10 +19,18 @@ _LOGGER = logging.getLogger(__name__)
ATTR_SENSOR_STATE
=
"
sensor_state
"
ATTR_SWITCH_MODE
=
"
switch_mode
"
ATTR_CURRENT_STATE_DETAIL
=
'
state_detail
'
MAKER_SWITCH_MOMENTARY
=
"
momentary
"
MAKER_SWITCH_TOGGLE
=
"
toggle
"
MAKER_SWITCH_MOMENTARY
=
"
momentary
"
MAKER_SWITCH_TOGGLE
=
"
toggle
"
WEMO_ON
=
1
WEMO_OFF
=
0
WEMO_STANDBY
=
8
# pylint: disable=unused-argument, too-many-function-args
def
setup_platform
(
hass
,
config
,
add_devices_callback
,
discovery_info
=
None
):
...
...
@@ -43,6 +52,7 @@ class WemoSwitch(SwitchDevice):
self
.
wemo
=
device
self
.
insight_params
=
None
self
.
maker_params
=
None
self
.
_state
=
None
wemo
=
get_component
(
'
wemo
'
)
wemo
.
SUBSCRIPTION_REGISTRY
.
register
(
self
.
wemo
)
...
...
@@ -88,17 +98,10 @@ class WemoSwitch(SwitchDevice):
else
:
attr
[
ATTR_SWITCH_MODE
]
=
MAKER_SWITCH_TOGGLE
return
attr
if
self
.
insight_params
:
attr
[
ATTR_CURRENT_STATE_DETAIL
]
=
self
.
detail_state
@property
def
state
(
self
):
"""
Returns the state.
"""
is_on
=
self
.
is_on
if
not
is_on
:
return
STATE_OFF
elif
self
.
is_standby
:
return
STATE_STANDBY
return
STATE_ON
return
attr
@property
def
current_power_mwh
(
self
):
...
...
@@ -113,21 +116,25 @@ class WemoSwitch(SwitchDevice):
return
self
.
insight_params
[
'
todaymw
'
]
@property
def
is_standby
(
self
):
def
detail_state
(
self
):
"""
Is the device on - or in standby.
"""
if
self
.
insight_params
:
standby_state
=
self
.
insight_params
[
'
state
'
]
# Standby is actually '8' but seems more defensive
# to check for the On and Off states
if
standby_state
==
'
1
'
or
standby_state
==
'
0
'
:
return
False
if
standby_state
==
WEMO_ON
:
return
STATE_OFF
elif
standby_state
==
WEMO_OFF
:
return
STATE_OFF
elif
standby_state
==
WEMO_STANDBY
:
return
STATE_STANDBY
else
:
return
True
return
STATE_UNKNOWN
@property
def
is_on
(
self
):
"""
True if switch is on.
"""
return
self
.
wemo
.
get
_state
()
"""
True if switch is on.
Standby is on!
"""
return
self
.
_state
@property
def
available
(
self
):
...
...
@@ -143,16 +150,20 @@ class WemoSwitch(SwitchDevice):
def
turn_on
(
self
,
**
kwargs
):
"""
Turns the switch on.
"""
self
.
_state
=
WEMO_ON
self
.
update_ha_state
()
self
.
wemo
.
on
()
def
turn_off
(
self
):
"""
Turns the switch off.
"""
self
.
_state
=
WEMO_OFF
self
.
update_ha_state
()
self
.
wemo
.
off
()
def
update
(
self
):
"""
Update WeMo state.
"""
try
:
self
.
wemo
.
get_state
(
True
)
self
.
_state
=
self
.
wemo
.
get_state
(
True
)
if
self
.
wemo
.
model_name
==
'
Insight
'
:
self
.
insight_params
=
self
.
wemo
.
insight_params
self
.
insight_params
[
'
standby_state
'
]
=
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment