-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75db36f
commit 03fdedc
Showing
119 changed files
with
14,297 additions
and
1,726 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
''' | ||
Created on August 15, 2022 | ||
This file is subject to the terms and conditions defined in the | ||
file 'LICENSE.txt', which is part of this source code package. | ||
@author: Edward Liu | ||
''' | ||
|
||
CONFIDENCE_OFFLINE = "confidence_device_offline" | ||
CONFIDENCE_LOW = "confidence_low" | ||
CONFIDENCE_MEDIUM = "confidence_medium" | ||
CONFIDENCE_HIGH = "confidence_high" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
''' | ||
Created on August 16, 2022 | ||
This file is subject to the terms and conditions defined in the | ||
file 'LICENSE.txt', which is part of this source code package. | ||
@author: Edward Liu | ||
''' | ||
|
||
from confidence.confidence_state import CONFIDENCE_OFFLINE | ||
from confidence.confidence_state import CONFIDENCE_LOW | ||
from confidence.confidence_state import CONFIDENCE_MEDIUM | ||
from confidence.confidence_state import CONFIDENCE_HIGH | ||
|
||
from devices.motion.motion import MotionDevice | ||
from devices.entry.entry import EntryDevice | ||
from devices.vayyar.vayyar import VayyarDevice | ||
from devices.lock.lock import LockDevice | ||
|
||
import utilities.utilities as utilities | ||
|
||
|
||
class OccupancyConfidenceStateMachine: | ||
|
||
def __init__(self): | ||
""" | ||
Instantiate this object | ||
""" | ||
# Away confidence state | ||
self.away_confidence_state = None | ||
|
||
# Home confidence state | ||
self.home_confidence_state = None | ||
|
||
self.away_reason = None | ||
|
||
self.home_reason = None | ||
|
||
def update_away_confidence_state(self, botengine, location_object): | ||
""" | ||
Update the confidence state based on the devices we installed. | ||
param: botengine | ||
param: location_object | ||
""" | ||
confidence_motion_points = 0 | ||
confidence_entry_points = 0 | ||
|
||
for device_id in location_object.devices: | ||
device = location_object.devices[device_id] | ||
if not device.is_connected: | ||
continue | ||
|
||
if isinstance(device, MotionDevice): | ||
if device.is_goal_id(MotionDevice.GOAL_MOTION_PROTECT_HOME): | ||
confidence_motion_points += 1 | ||
|
||
elif isinstance(device, VayyarDevice): | ||
confidence_motion_points += 1 | ||
|
||
elif isinstance(device, EntryDevice): | ||
if device.is_goal_id(EntryDevice.GOAL_PERIMETER_NORMAL): | ||
confidence_entry_points += 1 | ||
|
||
elif isinstance(device, LockDevice): | ||
confidence_entry_points += 1 | ||
|
||
if confidence_motion_points == 0 and confidence_entry_points == 0: | ||
state = CONFIDENCE_OFFLINE | ||
self.away_reason = _("We don't have enough Motion or Vayyar devices for occupancy away service to work.") | ||
|
||
elif confidence_motion_points > 1 and confidence_entry_points > 0: | ||
state = CONFIDENCE_HIGH | ||
self.away_reason = _("We have high confidence on the occupancy away service.") | ||
|
||
elif confidence_motion_points > 0 and confidence_entry_points > 0: | ||
state = CONFIDENCE_MEDIUM | ||
self.away_reason = _("Add 1 more Motion or Vayyar device to improve the confidence.") | ||
|
||
elif confidence_motion_points > 1: | ||
state = CONFIDENCE_MEDIUM | ||
self.away_reason = _("Add 1 more entry device to improve the confidence.") | ||
|
||
else: | ||
state = CONFIDENCE_LOW | ||
if confidence_motion_points > 0: | ||
self.away_reason = _("Add 1 Entry device to improve the confidence.") | ||
|
||
else: | ||
self.away_reason = _("Add 1 Motion or Vayyar device to improve the confidence.") | ||
|
||
if self.away_confidence_state is None or self.away_confidence_state != state: | ||
self.away_confidence_state = state | ||
|
||
def update_home_confidence_state(self, botengine, location_object): | ||
""" | ||
Update the confidence state based on the devices we installed. | ||
param: botengine | ||
param: location_object | ||
""" | ||
confidence_motion_points = 0 | ||
confidence_entry_points = 0 | ||
|
||
for device_id in location_object.devices: | ||
device = location_object.devices[device_id] | ||
if not device.is_connected: | ||
continue | ||
|
||
if isinstance(device, MotionDevice): | ||
if not device.is_goal_id(MotionDevice.GOAL_MOTION_PROTECT_HOME): | ||
continue | ||
confidence_motion_points += 1 | ||
|
||
elif isinstance(device, VayyarDevice): | ||
confidence_motion_points += 1 | ||
|
||
elif isinstance(device, EntryDevice): | ||
confidence_entry_points += 1 | ||
|
||
elif isinstance(device, LockDevice): | ||
confidence_entry_points += 1 | ||
|
||
if confidence_motion_points == 0 and confidence_entry_points == 0: | ||
state = CONFIDENCE_OFFLINE | ||
self.home_reason = _("We don't have Motion or Vayyar or Entry device for occupancy home service to work.") | ||
|
||
elif confidence_motion_points > 1 and confidence_entry_points > 0: | ||
state = CONFIDENCE_HIGH | ||
self.home_reason = _("We have high confidence on the occupancy home service.") | ||
|
||
elif confidence_motion_points > 0 and confidence_entry_points > 0: | ||
state = CONFIDENCE_MEDIUM | ||
self.home_reason = _("Add 1 Motion or Vayyar device to improve the confidence.") | ||
|
||
elif confidence_motion_points > 1: | ||
state = CONFIDENCE_MEDIUM | ||
self.home_reason = _("Add 1 Entry device to improve the confidence.") | ||
|
||
else: | ||
state = CONFIDENCE_LOW | ||
if confidence_motion_points > 0: | ||
self.home_reason = _("Add 1 Entry device to improve the confidence.") | ||
|
||
else: | ||
self.home_reason = _("Add 1 Motion or Vayyar device to improve the confidence.") | ||
|
||
if self.home_confidence_state is None or self.home_confidence_state != state: | ||
self.home_confidence_state = state | ||
|
||
def current_away_confidence(self): | ||
return self.away_confidence_state, self.away_reason | ||
|
||
def current_home_confidence(self): | ||
return self.home_confidence_state, self.home_reason | ||
|
||
def is_away_confidence_good(self): | ||
return self.away_confidence_state > CONFIDENCE_LOW | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
''' | ||
Created on August 15, 2022 | ||
This file is subject to the terms and conditions defined in the | ||
file 'LICENSE.txt', which is part of this source code package. | ||
@author: Edward Liu | ||
''' | ||
|
||
from confidence.confidence_state import CONFIDENCE_OFFLINE | ||
from confidence.confidence_state import CONFIDENCE_LOW | ||
from confidence.confidence_state import CONFIDENCE_MEDIUM | ||
from confidence.confidence_state import CONFIDENCE_HIGH | ||
|
||
from devices.motion.motion import MotionDevice | ||
from devices.vayyar.vayyar import VayyarDevice | ||
|
||
import utilities.utilities as utilities | ||
|
||
|
||
class SleepConfidenceStateMachine: | ||
|
||
def __init__(self): | ||
""" | ||
Instantiate this object | ||
""" | ||
# Confidence State | ||
self.state = None | ||
|
||
# Reason for the confidence state | ||
self.reason = None | ||
|
||
def update_confidence_state(self, botengine, location_object): | ||
""" | ||
Update the confidence state based on the devices we installed. | ||
param: botengine | ||
param: location_object | ||
""" | ||
confidence_normal_points = 0 | ||
confidence_timeout_exceeded = True # No Motion in last 12 hours | ||
confidence_in_bedroom_points = 0 | ||
confidence_out_bedroom_points = 0 | ||
|
||
for device_id in location_object.devices: | ||
device = location_object.devices[device_id] | ||
if not device.is_connected: | ||
continue | ||
|
||
if isinstance(device, MotionDevice): | ||
if not device.is_goal_id(MotionDevice.GOAL_MOTION_PROTECT_HOME): | ||
continue | ||
|
||
confidence_normal_points += 1 | ||
|
||
if MotionDevice.MEASUREMENT_NAME_STATUS in device.measurements: | ||
if botengine.get_timestamp() - device.measurements[MotionDevice.MEASUREMENT_NAME_STATUS][0][1] >= (utilities.ONE_HOUR_MS * 12): | ||
confidence_timeout_exceeded = True | ||
else: | ||
confidence_timeout_exceeded = False | ||
else: | ||
confidence_timeout_exceeded = True | ||
|
||
if device.is_in_bedroom(botengine): | ||
confidence_in_bedroom_points += 1 | ||
|
||
else: | ||
confidence_out_bedroom_points += 1 | ||
|
||
elif isinstance(device, VayyarDevice): | ||
confidence_normal_points += 1 | ||
|
||
if VayyarDevice.MEASUREMENT_NAME_OCCUPANCY_TARGET in device.measurements: | ||
if botengine.get_timestamp() - device.measurements[VayyarDevice.MEASUREMENT_NAME_OCCUPANCY_TARGET][0][1] >= (utilities.ONE_HOUR_MS * 12): | ||
confidence_timeout_exceeded = True | ||
else: | ||
confidence_timeout_exceeded = False | ||
else: | ||
confidence_timeout_exceeded = True | ||
|
||
if device.is_in_bedroom(botengine): | ||
confidence_in_bedroom_points += 1 | ||
|
||
else: | ||
confidence_out_bedroom_points += 1 | ||
|
||
if confidence_normal_points == 0: | ||
state = CONFIDENCE_OFFLINE | ||
self.reason = _("We don't have enough devices for sleep service to work.") | ||
|
||
else: | ||
if confidence_in_bedroom_points > 0 and confidence_out_bedroom_points > 1: | ||
if confidence_timeout_exceeded: | ||
state = CONFIDENCE_MEDIUM | ||
self.reason = _("We have medium confidence on the sleep service due to lack of recent measurements.") | ||
else: | ||
state = CONFIDENCE_HIGH | ||
self.reason = _("We have high confidence on the sleep service.") | ||
|
||
elif confidence_in_bedroom_points > 0 and confidence_out_bedroom_points > 0: | ||
if confidence_timeout_exceeded: | ||
state = CONFIDENCE_LOW | ||
self.reason = _("We have low confidence on the sleep service due to lack of recent measurements.") | ||
else: | ||
state = CONFIDENCE_MEDIUM | ||
self.reason = _("Add 1 more Motion or Vayyar device to improve the confidence.") | ||
|
||
else: | ||
state = CONFIDENCE_LOW | ||
if confidence_in_bedroom_points > 0: | ||
self.reason = _("Add more Motion or Vayyar devices installed outside bedroom to improve the confidence.") | ||
|
||
else: | ||
self.reason = _("Add more Motion or Vayyar devices installed inside bedroom to improve the confidence.") | ||
|
||
if self.state is None or self.state != state: | ||
self.state = state | ||
|
||
def current_state(self): | ||
return self.state | ||
|
||
def current_confidence(self): | ||
return self.state, self.reason |
Empty file.
Oops, something went wrong.