MTrab / landroid_cloud

Landroid Cloud component for Home Assistant
GNU General Public License v3.0
271 stars 33 forks source link

Cannot call service from javascript #223

Closed Barma-lej closed 2 years ago

Barma-lej commented 2 years ago

Environment:

Describe the bug

Hi, Malene. The other day I have tried to call service setzone from javascript (Description). And get an error: _'NoneType' object has no attribute 'deviceid'

this.hass.callService('landroid_cloud', 'setzone', { entity_id: 'vacuum.mower', zone: 1 });
this.hass.callService('landroid_cloud', 'setzone', { entity_id: 'vacuum.mower', zone: '1' });

Than i tried to change raindelay

this.hass.callService('landroid_cloud', 'config', { entity_id: 'vacuum.mower', config: 90, });
this.hass.callService('landroid_cloud', 'config', { entity_id: 'vacuum.mower', config: '90', });

And again i got the same error

After that i decided to call set_fan_speed for my vacuum cleaner. And that works without any problem

this.hass.callService('vacuum', 'set_fan_speed', { entity_id: 'vacuum.robi', fan_speed: 'Silent' });

Can you please check this line

I'm not sure that's error in your integration, but i can't find errors in javascript too πŸ˜’

Debug log


Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/landroid_cloud/services.py:118
Integration: Home Assistant WebSocket API ([documentation](https://www.home-assistant.io/integrations/websocket_api), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+websocket_api%22))
First occurred: 19 июля 2022 г., 20:06:08 (4 occurrences)
Last logged: 00:04:39

[140448154679424] 'NoneType' object has no attribute 'device_id'
[140447691906960] 'NoneType' object has no attribute 'device_id'
[140447692391136] 'NoneType' object has no attribute 'device_id'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 193, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1713, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1750, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/config/custom_components/landroid_cloud/services.py", line 118, in async_call_landroid_service
    entity_registry.entities.get(entry).device_id
AttributeError: 'NoneType' object has no attribute 'device_id'
MTrab commented 2 years ago

I'm not familiar with the Javascript calls in HA yet (haven't ventured into Lovelace developing yet) - but. If you view the YAML definition of calling a service, from the developer console, it would look like this, calling the service with an entity_id rather than device_id.

service: landroid_cloud.setzone
data:
  zone: '1'
target:
  entity_id: vacuum.back_left

How this would translate to javascript calls I don't know.

Barma-lej commented 2 years ago

Well, if i call a service with device_id it works:

this.hass.callService('landroid_cloud', 'setzone', { device_id: 'b2433e6xxxxxxxxxxx978e42cd0749', zone: 1, });

Doesn't work with entity_id

However, if i call a service for vacuum everithing works

this.hass.callService('vacuum', 'set_fan_speed', { entity_id: 'vacuum.robi', fan_speed: 'Silent' });

this is what it looks like in the developer console

service: vacuum.set_fan_speed
data:
  fan_speed: sw
target:
  entity_id: vacuum.robi
MTrab commented 2 years ago

Which model is your vacuum?

Barma-lej commented 2 years ago

Landroid Worx M500 WR141E Attrs:

battery_level: 64
battery_icon: mdi:battery-60
accessories: null
battery: 
cycles:
  total: 829
  current: 0
  reset_at: null
  reset_time: null
temperature: 30.2
voltage: 18.24
percent: 64
charging: false

blades: 
total_on: 74308
reset_at: 61657
reset_time: '2022-04-19T07:04:53+02:00'
current_on: 12651

error: 
id: 0
description: no error

firmware: 
auto_upgrade: false
version: 3.26

locked: false
mac_address: privat
model: Landroid M500
online: true
orientation: 
pitch: 1
roll: 2.9
yaw: 341.4

rain_sensor: 
delay: 60
triggered: false
remaining: 0

schedule: 
time_extension: 0
active: true
auto_schedule:
  settings: {}
  enabled: null
primary:
  monday:
    start: '11:00'
    end: '12:30'
    duration: 90
    boundary: false
  tuesday:
    start: '11:00'
    end: '12:30'
    duration: 90
    boundary: false
  wednesday:
    start: '11:00'
    end: '12:30'
    duration: 90
    boundary: true
  thursday:
    start: '11:00'
    end: '12:30'
    duration: 90
    boundary: false
  friday:
    start: '11:00'
    end: '12:30'
    duration: 90
    boundary: false
  saturday:
    start: '11:00'
    end: '12:30'
    duration: 90
    boundary: false
  sunday:
    start: '11:00'
    end: '12:30'
    duration: 90
    boundary: true
secondary:
  monday:
    start: '18:00'
    end: '19:30'
    duration: 90
    boundary: false
  tuesday:
    start: '18:00'
    end: '19:30'
    duration: 90
    boundary: false
  wednesday:
    start: '18:00'
    end: '19:30'
    duration: 90
    boundary: false
  thursday:
    start: '18:00'
    end: '19:30'
    duration: 90
    boundary: false
  friday:
    start: '18:00'
    end: '19:30'
    duration: 90
    boundary: false
  saturday:
    start: '18:00'
    end: '19:30'
    duration: 90
    boundary: false
  sunday:
    start: '18:00'
    end: '19:30'
    duration: 90
    boundary: false

serial_number: 20_12
status_info: 
id: 7
description: mowing

time_zone: Europe/Berlin
zone: 
current: 0
next: 0
index: 7
indicies:
  - 0
  - 0
  - 0
  - 0
  - 0
  - 0
  - 0
  - 0
  - 0
  - 0
starting_point:
  - 0
  - 0
  - 0
  - 0

capabilities: Edge Cut, One-Time-Schedule, Party Mode, Motor Torque
mqtt_connected: true
supported_landroid_features: 15359
party_mode_enabled: false
rssi: -81
statistics: 
worktime_blades_on: 74308
distance: 1194852
worktime_total: 77999

torque: -25
state_updated_at: 2022-07-20T11:39:19+02:00
device_class: landroid_cloud__state
friendly_name: Mower
supported_features: 12500
MTrab commented 2 years ago

Not your mower, your vacuum ;) Need to see what the difference could be, as the code is as it should be and it reacts when you set at target entity_id in the developer tools

Barma-lej commented 2 years ago

πŸ™ˆ i'm sorry

Roborock S50 Attributes:

fan_speed_list: Silent, Standard, Medium, Turbo, Gentle, Auto
battery_level: 100
battery_icon: mdi:battery-charging-100
fan_speed: Turbo
status: Charging
timers: 
- enabled: false
  cron: 37 15 * * 0,6
  next_schedule: '2022-07-24T13:37:00+00:00'

friendly_name: Robi
supported_features: 14204
MTrab commented 2 years ago

Which integration are you using for that one?

Barma-lej commented 2 years ago

Xiaomi miio Github

Xiaomi miio Home assistant

MTrab commented 2 years ago

Okay - that integration are not using the new target attributes in services.yaml, so that's the difference. The Miio integration have a field called entity_id, that's not the new standard way ;)

So you need to figure out how to set a target in the javascript

Barma-lej commented 2 years ago

But, call other services e.g. partymode, start, lock, without additionals options (zone: 1), are working well

MTrab commented 2 years ago

Hmmm - will need to do some testing then. Is it your own landroid card you have this issue in?

Barma-lej commented 2 years ago

Yes, the card is forked from vacuum card. I have seen a several cards and all of these cards call the services as described here

MTrab commented 2 years ago

Doesn't seem like zone calls do anything in v0.1.9 - nothing happens, not even an error.

Barma-lej commented 2 years ago

Yes, this is just a draft without calling any services.

MTrab commented 2 years ago

Okay - that makes debugging pretty difficult :D

Barma-lej commented 2 years ago

Returned in v0.2.0, executed with an error. Now you can debug πŸ™‚

Barma-lej commented 2 years ago

Fixed in landroid-card version 0.2.2

https://github.com/MTrab/landroid_cloud/blob/a65160f7b385e7c3386a06582ada8d7b49a4b6fd/custom_components/landroid_cloud/services.py#L116 If called service without additional parmeters, e.g. lock, partymode your python code get service_data[CONF_ENTITY_ID] as an array, otherwise as a string

Screenshot 2022-08-01 001151