klausmeyer / fritzbox-smarthome

🏡 💡 Ruby client for AVM Home Automation Interface
https://rubygems.org/gems/fritzbox-smarthome
MIT License
6 stars 5 forks source link

Define properties via ActiveModel::Attributes #51

Closed phoet closed 3 months ago

phoet commented 3 months ago

I was playing around with this gem for some home automation and it would be helpful for discoverability and ease of use to define the attributes in the Actor via ActiveModel::Attributes so that .attributes .to_h etc can be easily supported.

klausmeyer commented 3 months ago

Hi @phoet,

thanks for the suggestion. I did play around with it and if you want you can give it a try:

gem 'fritzbox-smarthome', '~> 0.8.0', github: 'klausmeyer/fritzbox-smarthome', branch: 'feat/am-attributes'
phoet commented 3 months ago

nice, looks good, will try it soonish

klausmeyer commented 3 months ago

@phoet friendly reminder ;)

phoet commented 3 months ago

ups, sorry. checked it out, works like a charm.

#!/usr/bin/env ruby

require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'
  gem 'fritzbox-smarthome', '~> 0.8.0', github: 'klausmeyer/fritzbox-smarthome', branch: 'feat/am-attributes'
end

require 'fritzbox/smarthome'

ain = ARGV[0]
abort("AIN is required") if ain.nil?

Fritzbox::Smarthome.configure do |config|
  config.endpoint   = 'http://fritz.box'
  config.username   = 'evcc'
  config.password   = 'XXX'
  config.verify_ssl = false
end

actor = Fritzbox::Smarthome::Actor.find_by!(ain: ain)
puts actor.attributes
klausmeyer commented 3 months ago

Nice. Thanks for verifying.

I will publish a new version soon.

klausmeyer commented 3 months ago

Here we go:

https://rubygems.org/gems/fritzbox-smarthome/versions/0.8.0