Example #1
0
    def get_targets(self, targets: str, level: str) -> list:
        """Return list of targets based on given level and targets string."""
        targets_split = targets.split(",")
        targets_list = []

        if level == self.NotificationLevel.emergency.value:
            if "everyone" in targets_split:
                targets_list.append(HOUSE[NOTIFIER])
                for person, attribute in PERSONS.items():
                    targets_list.append(attribute[NOTIFIER])
            else:
                if "home" in targets_split:
                    targets_list.append(HOUSE[NOTIFIER])
                for person, attribute in PERSONS.items():
                    if person in targets_split:
                        targets_list.append(attribute[NOTIFIER])
        else:
            if "everyone" in targets_split:
                targets_list.append(HOUSE[NOTIFIER])
                for person, attribute in PERSONS.items():
                    if self.target_available(person):
                        targets_list.append(attribute[NOTIFIER])
            else:
                if "home" in targets_split:
                    targets_list.append(HOUSE[NOTIFIER])
                for person, attribute in PERSONS.items():
                    if person in targets_split and self.target_available(
                            person):
                        targets_list.append(attribute[NOTIFIER])

        return targets_list
Example #2
0
 def who_in_state(self, *presence_states: Enum) -> list:
     """Return list of person in given state."""
     presence_state_list = [
         presence_state.value for presence_state in presence_states
     ]
     return [
         person for person, attribute in PERSONS.items()
         if self.get_state(attribute[PRESENCE_STATE]) in presence_state_list
     ]
Example #3
0
    def configure(self):
        """Configure."""
        self.briefing_list = {}

        for person, attribute in PERSONS.items():
            self.listen_state(
                self.someone_arrived,
                attribute[PRESENCE_STATE],
                new=self.presence_app.PresenceState.just_arrived.value,
                person=person,
            )

        self.listen_state(self.sleep_mode_deactivated,
                          MODES[SLEEP_MODE],
                          new=OFF)
Example #4
0
    def configure(self) -> None:
        """Configure."""
        for person, attribute in PERSONS.items():
            # get key topic for mqtt room device tracker
            keys_topic = attribute.get("keys_topic")
            # set initial state
            if self.get_state(attribute[KEYS]) == NOT_HOME:
                self.select_option(attribute[PRESENCE_STATE],
                                   self.PresenceState.away.value)
            else:
                self.select_option(attribute[PRESENCE_STATE],
                                   self.PresenceState.home.value)

            # away/extented away to just arrived
            self.listen_state(
                self.set_presence_person,
                attribute[KEYS],
                old=NOT_HOME,
                input_select=attribute[PRESENCE_STATE],
                person=person,
                key_topic=keys_topic,
                target_state=self.PresenceState.just_arrived.value,
            )

            # home to just left
            self.listen_state(
                self.set_presence_person,
                attribute[KEYS],
                new=NOT_HOME,
                input_select=attribute[PRESENCE_STATE],
                person=person,
                keys_topic=keys_topic,
                target_state=self.PresenceState.just_left.value,
            )

            # just arrived to home
            self.listen_state(
                self.set_presence_person,
                attribute[PRESENCE_STATE],
                new=self.PresenceState.just_arrived.value,
                duration=60 * 5,
                input_select=attribute[PRESENCE_STATE],
                person=person,
                keys_topic=keys_topic,
                target_state=self.PresenceState.home.value,
            )

            # just left to just arrived = home
            self.listen_state(
                self.set_presence_person,
                attribute[PRESENCE_STATE],
                old=self.PresenceState.just_left.value,
                new=self.PresenceState.just_arrived.value,
                input_select=attribute[PRESENCE_STATE],
                person=person,
                keys_topic=keys_topic,
                target_state=self.PresenceState.home.value,
            )

            # just left to away
            self.listen_state(
                self.set_presence_person,
                attribute[PRESENCE_STATE],
                new=self.PresenceState.just_left.value,
                duration=60 * 5,
                input_select=attribute[PRESENCE_STATE],
                person=person,
                keys_topic=keys_topic,
                target_state=self.PresenceState.away.value,
            )

            # away to extended away
            self.listen_state(
                self.set_presence_person,
                attribute[PRESENCE_STATE],
                new=self.PresenceState.away.value,
                duration=60 * 60 * 24,
                input_select=attribute[PRESENCE_STATE],
                person=person,
                keys_topic=keys_topic,
                target_state=self.PresenceState.extended_away.value,
            )

            # listen state to trigger house state change
            self.listen_state(self.set_presence_house,
                              attribute[PRESENCE_STATE])
Example #5
0
 def configure(self) -> None:
     """Configure."""
     for person, attribute in PERSONS.items():
         self.listen_state(
             self.phone_call_changed, attribute[PHONE_CALL_BOOL], person=person
         )