Author Topic: Device Driver API driver interface changes  (Read 1221 times)

John Hughes

  • Administrator
  • Hero Member
  • *****
  • Posts: 2851
    • View Profile
    • Codecore Technologies
Device Driver API driver interface changes
« on: June 06, 2012, 12:53:34 pm »
To support consistant paged list binding across drivers I updated several of the driver interfaces. The following driver interfaces have new paged list binding members (this is a breaking change):

* IClimateControlDriver
* ILightingAndElectricalDriver
* ISecurityDriver
* IWeatherDriver

For those users who have submitted drivers, I have already updated the source code to include the new members. Please request the updated driver source code and I will send you the changes.

These new members all must be decorated with the [SupportsPropertyBinding] attribute, and don't forget to call DevicePropertyChangeNotification() when anything changes that should update the paged list.

Here are examples of the new members:

IClimateControlDriver
Code: [Select]
        [ScriptObjectPropertyAttribute("Paged List Thermostats", "Provides the list of thermostats to be shown in a Touch Screen Interface's Paged List control. The item value has the following properties: ID. ID is the thermostat id.")]
        [SupportsDriverPropertyBinding]
        public ScriptPagedListCollection PagedListThermostats
        {
            get
            {
                var list = new List<ScriptPagedListItem>();


                foreach (var therm in _thermostatInfo)
                {
                    string title = therm.Name;
                    //TODO: support temperature scale.
                    string subtitle = therm.CurrentTemperature + "\u00B0  (" + therm.CoolSetPoint + "\u00B0/" + therm.HeatSetPoint + "\u00B0) " + therm.ThermostatMode.ToString().ToFriendlyName();
                    ScriptExpandoObject value = new ScriptExpandoObject();
                    value.SetProperty("ID", new ScriptNumber(therm.ThermostatNumber));

                    list.Add(new ScriptPagedListItem(title, subtitle, value));
                }

                return new ScriptPagedListCollection(list);
            }
        }

ILightingAndElectricalDriver
Code: [Select]
        [ScriptObjectPropertyAttribute("Paged List Lights", "Provides the list of lights to be shown in a Touch Screen Interface's Paged List control. The item value has the following properties: ID, IsDimmer. ID is the light id. IsDimmer indicates if the light is is a multilevel dimmer.")]
        [SupportsDriverPropertyBinding]
        public ScriptPagedListCollection PagedListLights
        {
            get
            {
                var list = new List<ScriptPagedListItem>();

                for (int i = 0; i < 256; i++)
                {
                    string title = "Light " + (i + 1);
                    string subtitle;
                    if (_lightLevels[i] == 0)
                        subtitle = "OFF";
                    else
                        subtitle = _lightLevels[i] + "%";
                    ScriptExpandoObject value = new ScriptExpandoObject();
                    value.SetProperty("ID", new ScriptNumber(i + 1));
                    value.SetProperty("IsDimmer", new ScriptBoolean(true)); // NOTE: all lights are dimmers in the simulator.

                    list.Add(new ScriptPagedListItem(title, subtitle, value));
                }

                return new ScriptPagedListCollection(list);
            }
        }

ISecurityDriver
Code: [Select]
        [ScriptObjectPropertyAttribute("Paged List Zone Statuses", "Provides the list of zone statuses to be shown in a Touch Screen Interface's Paged List control. The item value has the following properties: ID. ID is the zone id.")]
        [SupportsDriverPropertyBinding]
        public ScriptPagedListCollection PagedListZoneStatuses
        {
            get
            {
                var list = new List<ScriptPagedListItem>();


                for (int i = 0; i < 208; i++)
                {
                    // Only include areas with a name.
                    string title = "Zone " + (i + 1);
                    string subtitle = _zonePhysicalStatuses[i].ToString();
                    ScriptExpandoObject value = new ScriptExpandoObject();
                    value.SetProperty("ID", new ScriptNumber(i + 1));

                    list.Add(new ScriptPagedListItem(title, subtitle, value));
                }


                return new ScriptPagedListCollection(list);
            }
        }

        [ScriptObjectPropertyAttribute("Paged List Area Statuses", "Provides the list of area statuses to be shown in a Touch Screen Interface's Paged List control. The item value has the following properties: ID. ID is the area id.")]
        [SupportsDriverPropertyBinding]
        public ScriptPagedListCollection PagedListAreaStatuses
        {
            get
            {
                var list = new List<ScriptPagedListItem>();


                for (int i = 0; i < 208; i++)
                {
                    // Only include areas with a name.
                    string title = "Area " + (i + 1);
                    string subtitle = _areaArmStatuses[i].ToString().ToFriendlyName();
                    subtitle += " - " + _areaArmUpStates[i].ToString().ToFriendlyName();
                    //if (_areaAlarmStates[i] != alarmState.NoAlarmActive)
                    //    subtitle += " - " + _areaAlarmStates[i].ToString().ToFriendlyName();
                    ScriptExpandoObject value = new ScriptExpandoObject();
                    value.SetProperty("ID", new ScriptNumber(i + 1));

                    list.Add(new ScriptPagedListItem(title, subtitle, value));
                }

                return new ScriptPagedListCollection(list);
            }
        }

IWeatherDriver
Code: [Select]
        [ScriptObjectPropertyAttribute("Paged List Forecast", "Provides the list of daily forcasts to be shown in a Touch Screen Interface's Paged List control. The item value has the following properties: Index. Index is the index for the weather driver property arrays.")]
        [SupportsDriverPropertyBinding]
        public ScriptPagedListCollection PagedListForecast
        {
            get
            {
                var dates = this.Dates;
                var highs = this.Highs;
                var lows = this.Lows;
                var conditions = this.Conditions;

                var list = new List<ScriptPagedListItem>();

                // Add dates.
                for (int i = dates.PrimitiveLowestIndex; i <= dates.PrimitiveHighestIndex; i++)
                {
                    string title = ((DateTime)(ScriptDateTime)dates[i]).ToString("dddd"); // full day of week name. ex: "Monday"
                    string subtitle = (int)(ScriptNumber)highs[i] + "\u00B0 / " + (int)(ScriptNumber)lows[i] + "\u00B0  " + (string)(ScriptString)conditions[i];
                    ScriptExpandoObject value = new ScriptExpandoObject();
                    value.SetProperty("Index", new ScriptNumber(i));

                    list.Add(new ScriptPagedListItem(title, subtitle, value));
                }

                return new ScriptPagedListCollection(list);
            }
        }

        [ScriptObjectPropertyAttribute("Paged List Forecast With Current Condition", "Provides the current condition and a list of daily forcasts to be shown in a Touch Screen Interface's Paged List control. The item value has the following properties: Index. Index is the index for the weather driver property arrays.")]
        [SupportsDriverPropertyBinding]
        public ScriptPagedListCollection PagedListForecastWithCurrentCondition
        {
            get
            {
                var list = PagedListForecast;

                // Insert current condition
                string title = "Current";
                string subtitle = (int)this.Temperature + "\u00B0" + "  " + (string)this.CurrentCondition;
                ScriptExpandoObject value = new ScriptExpandoObject();
                value.SetProperty("Index", new ScriptNumber(0));
                list.Insert(0, new ScriptPagedListItem(title, subtitle, value));

                return list;
            }
        }
John Hughes
Codecore Technologies