Skip to content

Instantly share code, notes, and snippets.

@darthdeus
Forked from ohcibi/init.coffee
Last active December 13, 2015 18:59
Show Gist options
  • Save darthdeus/4959807 to your computer and use it in GitHub Desktop.
Save darthdeus/4959807 to your computer and use it in GitHub Desktop.
Ember.Handlebars.registerBoundHelper 'forMoreThanOneIn', (collection) ->
alert collection.toArray()
return elseFn() if collection.length == 1
return "Compound"
window.App = Ember.Application.create
rootElement: "#QiviconBasicClient"
App.Router.map -> @resource 'rooms'
App.IndexRoute = Ember.Route.extend redirect: -> @transitionTo 'rooms'
# Controllers
App.RoomsController = Ember.ArrayController.extend
sortProperties: ['room_id']
# Routes
App.RoomsRoute = Ember.Route.extend
setupController: (controller) -> controller.set("content", App.Room.find())
# Models
App.Store = DS.Store.extend
revision: 11
adapter: DS.FixtureAdapter
App.Room = DS.Model.extend
room_id: DS.attr 'string'
name: DS.attr 'string'
devices: DS.hasMany 'App.CompoundDevice'
App.CompoundDevice = DS.Model.extend
name: DS.attr 'string'
type: DS.attr 'string'
compound_device_id: DS.attr 'string'
room: DS.belongsTo 'App.Room'
devices: DS.hasMany 'App.Device'
App.Device = DS.Model.extend
device_class: DS.attr 'string'
device_name: DS.attr 'string'
device_id: DS.attr 'string'
states: DS.hasMany 'App.DeviceState'
compound_device: DS.belongsTo 'App.CompoundDevice'
App.DeviceState = DS.Model.extend
name: DS.attr 'string'
value: DS.attr 'string'
device: DS.belongsTo 'App.Device'
# Fixtures
App.Room.FIXTURES = [
{id: 1, name: "Wohnzimmer" , room_id: "hz_1" , devices: [2]}
{id: 2, name: "Schlafzimmer" , room_id: "hz_2"}
{id: 3, name: "Küche" , room_id: "hz_3" , devices: [4]}
{id: 4, name: "Bad" , room_id: "hz_4" , devices: [1, 5]}
{id: 5, name: "Flur" , room_id: "hz_5"}
{id: 6, name: "Garten" , room_id: "hz_6" , devices: [3]}
]
App.CompoundDevice.FIXTURES = [
{id: 1, name: "MyContactDetector" , type: "ContactDetector" , compound_device_id: "yyy1", room: 4 , devices: [1]}
{id: 2, name: "MyDimmer" , type: "DimmableSocket" , compound_device_id: "yyy2", room: 1 , devices: [2]}
{id: 3, name: "MySwitch" , type: "OnOffSocket" , compound_device_id: "yyy3", room: 6 , devices: [3]}
{id: 4, name: "MyOnOffMeter" , type: "OnOffMeter" , compound_device_id: "yyy4", room: 3 , devices: [4, 5]}
{id: 5, name: "MyThermostat" , type: "Thermostat" , compound_device_id: "yyy5", room: 4 , devices: [6, 7, 8]}
]
App.Device.FIXTURES = [
{id: 1, device_class: "binarySensor" , name: "ContactDetector" , device_id: "xxx1" , states: [1] , compound_device: 1}
{id: 2, device_class: "multiLevelSwitch" , name: "DimmableSocket" , device_id: "xxx2" , states: [2, 3], compound_device: 2}
{id: 3, device_class: "binarySwitch" , name: "OnOffSocket" , device_id: "xxx3" , states: [4] , compound_device: 3}
{id: 4, device_class: "binarySwitch" , name: "EnergyMeter" , device_id: "xxx4" , states: [5] , compound_device: 4}
{id: 5, device_class: "meter" , name: "EnergyMeter" , device_id: "xxx5" , states: [6, 7], compound_device: 4}
{id: 6, device_class: "multiLevelSensor" , name: "TemperatureSensor", device_id: "xxx6" , states: [8] , compound_device: 5}
{id: 7, device_class: "multiLevelSensor" , name: "HumiditySensor" , device_id: "xxx7" , states: [9] , compound_device: 5}
{id: 8, device_class: "temperatureActuator", name: "Thermostat" , device_id: "xxx8" , states: [10] , compound_device: 5}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment