Esempio n. 1
0
    /// <summary>
    ///     Initialize, is automatically run by the daemon
    /// </summary>
    public override void Initialize()
    {
        // Set up the state management

        // When chromecast is going off
        // Entities("media_player.tv_nere")
        //     .StateChanges
        //     .Where(e => e.New?.State == "off" && e.Old?.State is object )
        //     .Subscribe(s =>
        //    {
        //        if (TvIsOn)
        //        {
        //            Log('TV is off, turnin off shield and tv')
        //            RunScript("tv_off_scene");
        //        }
        //    });
        // When state change on my media players, call OnMediaStateChanged
        Entities(TvMediaPlayers !)
        .StateChanges
        .Subscribe(s =>
        {
            OnMediaStateChanged(s.New, s.Old);
        });

        // When TV on (remote on), call OnTvTurnedOn
        Entity(RemoteTVRummet !)
        .StateChanges
        .Where(e =>
               e.Old?.State == "off" &&
               e.New?.State == "on")
        .Subscribe(s =>
        {
            LogDebug("TV remote status change from {from} to {to}", s.Old?.State, s.New?.State);
            OnTVTurnedOn();
        });


        // When ever TV remote activity changes, ie TV, Film, Poweroff call OnTvActivityChange
        Entity(RemoteTVRummet !)
        .StateAllChanges
        .Where(e => e.New?.Attribute?.current_activity != e.Old?.Attribute?.current_activity)
        .Subscribe(s =>
        {
            LogDebug("TV remote activity change from {from} to {to}", s.Old?.Attribute?.current_activity, s.New?.Attribute?.current_activity);
            OnTvActivityChange(s.New);
        });
    }
Esempio n. 2
0
    /// <summary>
    ///     Initialize, is automatically run by the daemon
    /// </summary>
    public override void Initialize()
    {
        // Set up the state management

        // When chromecast is going off
        // Entities("media_player.tv_nere")
        //     .StateChanges
        //     .Where(e => e.New?.State == "off" && e.Old?.State is object )
        //     .Subscribe(s =>
        //    {
        //        if (TvIsOn)
        //        {
        //            Log('TV is off, turnin off shield and tv')
        //            RunScript("tv_off_scene");
        //        }
        //    });
        // When state change on my media players, call OnMediaStateChanged
        Entities(TvMediaPlayers !)
        .StateChanges
        .Subscribe(s => OnMediaStateChanged(s.New, s.Old));

        // When TV on (remote on), call OnTvTurnedOn
        Entity(RemoteTVRummet !)
        .StateChanges
        .Where(e =>
               e.Old?.State == "off" &&
               e.New?.State == "on")
        .Subscribe(s => OnTVTurnedOn());


        // When ever TV remote activity changes, ie TV, Film, Poweroff call OnTvActivityChange
        Entity(RemoteTVRummet !)
        .StateAllChanges
        .Where(e => e.New?.Attribute?.current_activity != e.Old?.Attribute?.current_activity)
        .Subscribe(s => OnTvActivityChange(s.New));

        // This function does not contain any async calls so just return completed task
        // return Task.CompletedTask;
    }
Esempio n. 3
0
    /// <summary>
    ///     Initialize, is automatically run by the daemon
    /// </summary>
    public override void Initialize()
    {
        // Set up the state management

        // When state change on my media players, call OnMediaStateChanged
        Entities(TvMediaPlayers !)
        .StateChanges
        .Subscribe(s => OnMediaStateChanged(s.New, s.Old));

        // When TV on (remote on), call OnTvTurnedOn
        Entity(RemoteTVRummet !)
        .StateChanges
        .Where(e => e.New?.State == "on")
        .Subscribe(s => OnTVTurnedOn());

        // When ever TV remote activity changes, ie TV, Film, Poweroff call OnTvActivityChange
        Entity(RemoteTVRummet !)
        .StateAllChanges
        .Where(e => e.New?.Attribute?.current_activity != e.Old?.Attribute?.current_activity)
        .Subscribe(s => OnTvActivityChange(s.New));

        // This function does not contain any async calls so just return completed task
        // return Task.CompletedTask;
    }